Add error screen

This commit is contained in:
Davide Depau 2018-09-02 01:58:32 +02:00
parent afd41952b4
commit dcf7ce8451
Signed by: depau
GPG key ID: C7D999B6A55EFE86
8 changed files with 142 additions and 17 deletions

View file

@ -41,6 +41,7 @@ dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-rc01'
implementation 'com.android.support:appcompat-v7:28.0.0-rc02'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'

View file

@ -16,20 +16,20 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".activities.StartActivity"
android:label="@string/app_name"
android:theme="@style/MaterialAppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.LicensesActivity"
android:label="@string/licenses"
android:theme="@style/MaterialAppTheme">
<activity
android:name=".activities.LicensesActivity"
android:label="@string/licenses"
android:theme="@style/MaterialAppTheme">
</activity>
<activity
android:name=".activities.UsbDrivePickerActivity"
@ -50,12 +50,22 @@
android:value="eu.depau.etchdroid.activities.UsbDrivePickerActivity"/>
</activity>
<activity
android:name=".activities.ErrorActivity"
android:launchMode="singleTask"
android:taskAffinity=""
android:label="@string/write_failed"
android:excludeFromRecents="true"
>
</activity>
<service
android:name=".services.UsbApiImgWriteService"
android:exported="false"/>
<service
android:name=".services.UsbApiDmgWriteService"
android:exported="false"/>
</application>
</manifest>

View file

@ -0,0 +1,21 @@
package eu.depau.etchdroid.activities
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import eu.depau.etchdroid.R
import kotlinx.android.synthetic.main.activity_error.*
class ErrorActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_error)
val msg = intent.getStringExtra("error")
error_message.text = msg
if ("errno 88" in msg)
troubleshooting_info.text = getString(R.string.troubleshoot_sock_op_on_non_sock)
else
troubleshooting_info.text = getString(R.string.unknown_error)
}
}

View file

@ -101,9 +101,9 @@ abstract class UsbApiWriteService(name: String) : UsbWriteService(name) {
try {
writtenBytes = writeInputStream(inputStream, msDev, sendProgress)
resultNotification(usbDevice.name, uri.getFileName(this)!!, true, writtenBytes, startTime)
resultNotification(usbDevice.name, uri.getFileName(this)!!, null, writtenBytes, startTime)
} catch (e: Exception) {
resultNotification(usbDevice.name, uri.getFileName(this)!!, false, writtenBytes, startTime)
resultNotification(usbDevice.name, uri.getFileName(this)!!, e, writtenBytes, startTime)
Log.e(TAG, "Could't write image to ${usbDevice.name}")
throw e
} finally {

View file

@ -1,15 +1,13 @@
package eu.depau.etchdroid.services
import android.app.IntentService
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.*
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.PowerManager
import androidx.core.app.NotificationCompat
import eu.depau.etchdroid.R
import eu.depau.etchdroid.activities.ErrorActivity
import eu.depau.etchdroid.kotlin_exts.toHRSize
import eu.depau.etchdroid.kotlin_exts.toHRTime
import java.util.*
@ -89,7 +87,7 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
notificationManager.notify(FOREGROUND_ID, buildForegroundNotification(usbDevice, filename, progr, "$progr% • $speed/s"))
}
fun resultNotification(usbDevice: String, filename: String, success: Boolean, bytes: Long = 0, startTime: Long = 0) {
fun resultNotification(usbDevice: String, filename: String, exception: Throwable?, bytes: Long = 0, startTime: Long = 0) {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
val b = getNotificationBuilder(WRITE_RESULT_CHANNEL_ID)
@ -97,11 +95,18 @@ abstract class UsbWriteService(name: String) : IntentService(name) {
val dt = System.currentTimeMillis() - startTime
if (!success)
b.setContentTitle(getString(R.string.write_failed))
if (exception != null) {
val intent = Intent(this, ErrorActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
intent.putExtra("error", exception.message)
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
b.setContentTitle(getString(R.string.write_failed_tap_for_info))
.setContentText(getString(R.string.error_notif_content_text, usbDevice))
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setSubText(dt.toHRTime())
else {
} else {
val speed = max(bytes.toDouble() / dt.toDouble() * 1000, 0.0).toHRSize() + "/s"
b.setContentTitle(getString(R.string.write_finished))
.setContentText(getString(R.string.success_notif_content_text, filename, usbDevice))

View file

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/row_padding"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/row_padding"
android:orientation="vertical"
tools:context=".activities.ErrorActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:text="@string/write_failed"
android:textColor="@color/name"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/operation_failed_because"/>
<TextView
android:id="@+id/error_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="monospace"
android:textIsSelectable="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingTop="@dimen/row_padding"
android:text="@string/troubleshooting_info"
android:textColor="@color/name"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/troubleshooting_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:autoLink="web" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:paddingTop="@dimen/row_padding"
android:text="@string/reporting_issues"
android:textColor="@color/name"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="@string/reporting_issues_text"
android:autoLink="web" />
</LinearLayout>

View file

@ -91,8 +91,15 @@
<string name="storagechooser_license_description">Selettore file DMG</string>
<string name="result_channel_desc">Utilizzato per mostrare il risultato di un\'operazione di scrittura terminata</string>
<string name="result_channel_name">Risultati scrittura USB</string>
<string name="write_failed">Scrittura fallita</string>
<string name="write_failed_tap_for_info">Scrittura fallita • Tocca per i dettagli</string>
<string name="write_finished">Scrittura terminata</string>
<string name="error_notif_content_text">%1$s potrebbe essere stato rimosso durante la scrittura.</string>
<string name="success_notif_content_text">%1$s scritto con successo su %2$s</string>
<string name="troubleshooting_info">Risoluzione dei problemi</string>
<string name="operation_failed_because">L\'operazione non è stata completata a causa del seguente errore:</string>
<string name="troubleshoot_sock_op_on_non_sock">Questo è un errore comune. In genere succede quando il dispositivo USB viene scollegato mentre è in corso una scrittura o quando è connesso attraverso un hub USB. Su qualche dispositivo, invece, è presente un problema nel sottosistema USB di Android: solitamente un riavvio lo risolve per un po\' di tempo.\n\nProva questi suggerimenti:\n• Stacca e riattacca il dispositivo USB, quindi riavvia l\'app\n• Riavvia il dispositivo (davvero, fallo)\n• Prova un\'altro dispositivo USB\n• Evita di usare adattatori o hub se non necessari\n• Evita di usare il telefono mentre sta scrivendo immagini\n• Sostituisci un adattatore USB On-The-Go difettoso</string>
<string name="reporting_issues">Segnalazione dei problemi</string>
<string name="reporting_issues_text">I problemi possono essere segnalati su GitHub:\nhttps://github.com/Depau/EtchDroid/issues</string>
<string name="write_failed">Scrittura fallita</string>
<string name="unknown_error">Errore sconosciuto. Prova a ricollegare il dispositivo USB o a riavviare il dispositivo. Per favore, segnala il problema su GitHub.</string>
</resources>

View file

@ -90,8 +90,15 @@
<string name="storagechooser_license_description">DMG file selector</string>
<string name="result_channel_desc">Used to display the result of a finished write operation</string>
<string name="result_channel_name">USB write result notifications</string>
<string name="write_failed">Write failed</string>
<string name="write_failed_tap_for_info">Write failed • Tap for info</string>
<string name="write_finished">Write finished</string>
<string name="error_notif_content_text">%1$s may have been unplugged while writing.</string>
<string name="success_notif_content_text">%1$s successfully written to %2$s</string>
<string name="troubleshooting_info">Troubleshooting information</string>
<string name="operation_failed_because">The operation could not be completed because the following error occurred:</string>
<string name="troubleshoot_sock_op_on_non_sock">This is a common error. Usually this happens when the USB drive is unplugged while it\'s being written to, or when it\'s connected through a USB hub. On some devices there might be a bug in Android\'s USB subsystem: usually a reboot will fix it for some time. \n\nTry these:\n• Unplug and re-plug the USB device, then restart the app\n• Reboot your device (really, try it)\n• Try another USB drive\n• Avoid using unnecessary adapters, dongles or hubs\n• Avoid using your phone while it\'s writing\n• Replace defective USB On-The-Go adapters\n\nIf the problem persists, please file an issue on GitHub.</string>
<string name="reporting_issues">Reporting issues</string>
<string name="reporting_issues_text">Issues can be reported on GitHub:\nhttps://github.com/Depau/EtchDroid/issues</string>
<string name="write_failed">Write failed</string>
<string name="unknown_error">Unknown error. Try to reattach the USB drive or reboot the device. Please file an issue on GitHub.</string>
</resources>