Skip to content
Merged
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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ release, a pull request cuts that heading to the version. The release run makes
section the body of the GitHub release, and refuses a version without one. `scripts/store-copy.py` writes Play's
"What's new" from the same section, under 500 characters per locale.

## Unreleased

- Text documents show their page headers and footers when pages are on, and number headings
and lists as LibreOffice does.
- Shapes and slides show their gradients, patterns, background pictures, shadows and Fontwork
text.
- Slides no longer show "Click to edit" placeholders from their master.
- When the system blocks the app's Network permission, as GrapheneOS can, the app says so and
opens its settings. Documents never leave the device.

## 4.24.0

- Free edition: a yearly subscription removes the ads and turns on all Pro features. "Support
Expand Down
45 changes: 38 additions & 7 deletions app/src/main/java/app/opendocument/droid/background/CoreLoader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ class CoreLoader(private val context: Context) {
// loads the native library and points the core at a usable temporary directory
initializeCore(context)

startSharedServer(crashManager)
try {
startSharedServer(crashManager)
} catch (e: NetworkDenied) {
// the first document asks again, and says so if it is still refused
Log.w(TAG, "core server denied a socket", e)
}
}

/**
Expand Down Expand Up @@ -114,7 +119,7 @@ class CoreLoader(private val context: Context) {
askEditing: Boolean = false,
declaredType: FileType? = null,
): List<HostedView> {
val server = checkNotNull(sharedServer) { "core server is not running" }
val server = startSharedServer(crashManager)

Log.i(TAG, "host file")

Expand Down Expand Up @@ -429,6 +434,12 @@ class CoreLoader(private val context: Context) {
/** An encrypted file whose format odrcore cannot decrypt, whatever the password. */
class UndecryptableFile(path: String) : IOException("cannot be decrypted: $path")

/**
* The system refuses the app any socket, as GrapheneOS does to an app without the Network
* permission, so the core server cannot serve the document to the WebView.
*/
class NetworkDenied(cause: Throwable) : IOException("core server denied a socket", cause)

companion object {
private const val TAG = "CoreLoader"

Expand Down Expand Up @@ -458,6 +469,18 @@ class CoreLoader(private val context: Context) {
private fun bind(server: HttpServer, crashManager: CrashManager): Int {
try {
return server.bind(SERVER_BIND_ADDRESS, PREFERRED_SERVER_PORT)
} catch (e: OdrException) {
// no other port is going to be granted either
if (e.code == SERVER_SOCKET_DENIED) {
throw NetworkDenied(e)
}

crashManager.log(
IOException(
"core server cannot bind $SERVER_BIND_ADDRESS:$PREFERRED_SERVER_PORT",
e,
)
)
} catch (e: Throwable) {
crashManager.log(
IOException(
Expand All @@ -478,17 +501,20 @@ class CoreLoader(private val context: Context) {
return PREFERRED_SERVER_PORT
}

/** Starts [sharedServer] if this is the first loader to ask. */
/**
* Starts [sharedServer] if this is the first loader to ask, or the last one was refused a
* socket. Throws [NetworkDenied] while the system refuses one.
*/
@Synchronized
private fun startSharedServer(crashManager: CrashManager) {
if (sharedServer != null) {
return
private fun startSharedServer(crashManager: CrashManager): HttpServer {
sharedServer?.let {
return it
}

val server = HttpServer()

sharedServer = server
sharedServerPort = bind(server, crashManager)
sharedServer = server

Thread {
try {
Expand All @@ -503,6 +529,8 @@ class CoreLoader(private val context: Context) {
it.name = "odr-http-server"
it.start()
}

return server
}

/** The loopback address the server binds to. */
Expand All @@ -515,6 +543,9 @@ class CoreLoader(private val context: Context) {
*/
private const val SERVER_URL_HOST = "localhost"

/** `odr::ErrorCode::server_socket_denied`, which has no [OdrException] subclass. */
private const val SERVER_SOCKET_DENIED = 53

/** What a bind asks for when any free port will do. */
private const val ANY_PORT = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class DocumentLoader(application: Application) : AndroidViewModel(application) {
encrypted(request, file, e)
} catch (e: OdrException.DecryptionFailed) {
encrypted(request, file, e)
} catch (e: CoreLoader.NetworkDenied) {
// the user's setting, not a bug: reported, not logged as a crash
report("load_error_network_denied", file)

deliver { it.onError(request, file, e) }
} catch (e: Throwable) {
failed("load_odf_error", file, request, e)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.net.Uri
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.provider.Settings
import android.text.InputType
import android.text.SpannableString
import android.text.Spanned
Expand All @@ -27,6 +28,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import app.opendocument.droid.R
import app.opendocument.droid.background.CoreLoader
import app.opendocument.droid.background.DocumentDarkening
import app.opendocument.droid.background.DocumentLoader
import app.opendocument.droid.background.DocumentRequest
Expand Down Expand Up @@ -1033,6 +1035,14 @@ class DocumentFragment : Fragment(), DocumentLoader.Listener {
offerReopen(activity, R.string.toast_error_find_file, true)
error is OutOfMemoryError ->
offerReopen(activity, R.string.toast_error_out_of_memory, true)
error is CoreLoader.NetworkDenied -> {
state.endLoadIdling()
giveUp(activity)

offerNetworkPermission(activity)

return
}
// unreadable, or named and still not openable
else -> {
// nothing is ever going to be shown for this file, so drop back to the
Expand Down Expand Up @@ -1182,6 +1192,30 @@ class DocumentFragment : Fragment(), DocumentLoader.Listener {
(activity as MainActivity).closeFailedDocument()
}

/**
* Explains that the app is denied a socket, as GrapheneOS does without the Network permission,
* and offers the app's settings to grant it.
*/
private fun offerNetworkPermission(activity: Activity) {
analyticsManager.report("network_permission_offer")

// strings off the activity: giveUp() already detached this fragment
AlertDialog.Builder(activity)
.setTitle(R.string.dialog_network_denied_title)
.setMessage(R.string.dialog_network_denied)
.setPositiveButton(R.string.dialog_network_denied_settings) { _, _ ->
val intent =
Intent(
Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", activity.packageName, null),
)

activity.startActivity(intent)
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}

private fun offerContact(activity: Activity) {
analyticsManager.report("contact_offer")

Expand Down
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,9 @@

<string name="dialog_broken_file_title">Couldn\'t open this file</string>
<string name="dialog_broken_file">The file may be damaged, or something went wrong on our side. If you think the file is fine, tell us at support@opendocument.app</string>
<string name="dialog_network_denied_title">Network access is off</string>
<string name="dialog_network_denied">This app shows documents through a connection that stays on your device, so it needs the Network permission. It does not send your files anywhere. Turn on Network in the app\'s settings, then open the file again.</string>
<string name="dialog_network_denied_settings">Open settings</string>
<string name="toast_error_find_file">Couldn\'t find file. Maybe it doesn\'t exist any longer?</string>
<string name="toast_error_illegal_file_reopen">Unsupported file format. Try opening it in another app.</string>
<!-- a sheet bigger than the device can lay out - see SpreadsheetBudget -->
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ googleJavaFormat = "1.35.0"
ktfmt = "0.64"

# odrcore's JNI bindings, java and native in one AAR, published from OpenDocument.core
odrCore = "7.7.0"
odrCore = "7.8.0"

# Strips the core's native libraries and extracts their symbols. CI installs this version.
ndk = "28.2.13676358"
Expand Down
Loading