From 965aeaca33b5ff7a46a2f7d1d09e1ee5907e8ebb Mon Sep 17 00:00:00 2001 From: mpl Date: Thu, 20 Sep 2018 03:03:19 +0200 Subject: [PATCH] clients/android: bump targetSdkVersion to 26 Because it is mandatory as of nov 2018: https://android-developers.googleblog.com/2017/12/improving-app-security-and-performance.html As the default Notification.Builder constructor is deprecated in API 26, this change also adds the use of the new constructor, which requires a notification channel Id. Note: since the users are now in full-control of the notifications, they can now choose to completely block the auto-upload notification channel. Given that the main goal of the notification was to keep the app in memory in order for auto-upload to work, one could expect that blocking the channel would defeat the notification's purpose. However, as far as I could test, auto-uploading seems to still be working even after disabling the channel, and letting the activity die (tip: in devoloper options, one can tick "Don't keep activities"). In fact, Perkeep Uploader still always runs as a service. Also build pk-put shipped in the app with Go 1.11. Fixes #1202 Change-Id: I8f98e0df742915cb504b6c1cfaa42ca6dc7b6189 --- clients/android/app/build.gradle | 6 ++--- .../android/app/src/main/AndroidManifest.xml | 2 +- .../java/org/camlistore/UploadService.java | 22 ++++++++++++++----- .../app/src/main/res/values/strings.xml | 5 +++-- clients/android/devenv/Dockerfile | 6 ++--- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/clients/android/app/build.gradle b/clients/android/app/build.gradle index ede569e63..4075334af 100644 --- a/clients/android/app/build.gradle +++ b/clients/android/app/build.gradle @@ -34,7 +34,7 @@ android { minSdkVersion 14 // Stay below API 26 for a while, because it deprecates the Notification Builder // constructor we're using. - targetSdkVersion 21 + targetSdkVersion 26 // integer. used by android to prevent downgrades. not seen by user. versionCode 4 // version shown to the user in play store. @@ -49,6 +49,6 @@ android { dependencies { implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'com.android.support:appcompat-v7:25.0.0' - implementation 'com.android.support:support-compat:25.0.0' + implementation 'com.android.support:appcompat-v7:26.0.0' + implementation 'com.android.support:support-compat:26.0.0' } diff --git a/clients/android/app/src/main/AndroidManifest.xml b/clients/android/app/src/main/AndroidManifest.xml index 2bbf0815e..11f562d39 100644 --- a/clients/android/app/src/main/AndroidManifest.xml +++ b/clients/android/app/src/main/AndroidManifest.xml @@ -7,7 +7,7 @@ android:versionCode="2" android:versionName="0.6.1"> - + diff --git a/clients/android/app/src/main/java/org/camlistore/UploadService.java b/clients/android/app/src/main/java/org/camlistore/UploadService.java index 3e72032df..6db858d9a 100644 --- a/clients/android/app/src/main/java/org/camlistore/UploadService.java +++ b/clients/android/app/src/main/java/org/camlistore/UploadService.java @@ -31,6 +31,7 @@ import org.camlistore.UploadThread.CamputChunkUploadedMessage; import org.camlistore.UploadThread.CamputStatsMessage; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -40,6 +41,7 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.net.wifi.WifiManager; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.FileObserver; @@ -72,6 +74,7 @@ public class UploadService extends Service { // thread exits private Notification.Builder mNotificationBuilder; // null until upload is // started/resumed + private NotificationChannel mNotificationChannel; private int mLastNotificationProgress = 0; // last computed value of the uploaded bytes, to avoid excessive notification updates private final Map mFileBytesRemain = new HashMap(); private final LinkedList mQueueList = new LinkedList(); @@ -130,11 +133,20 @@ public class UploadService extends Service { stackBuilder.addNextIntent(notificationIntent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); - autoUploadNotif = - // TODO(mpl): use API 26 Constructor with a notification channel later, when - // Android >=8 is more widely distributed. - new Notification.Builder(this) - .setContentTitle(getText(R.string.notification_title)) + // Create the NotificationChannel, but only on API 26+ because + // the NotificationChannel class is new and not in the support library + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + mNotificationChannel = new NotificationChannel(getString(R.string.channel_id), + getText(R.string.channel_name), NotificationManager.IMPORTANCE_DEFAULT); + mNotificationChannel.setDescription(getString(R.string.channel_description)); + // Register the channel with the system; you can't change the importance + // or other notification behaviors after this + mNotificationManager.createNotificationChannel(mNotificationChannel); + autoUploadNotif = new Notification.Builder(this, getString(R.string.channel_id)); + } else { + autoUploadNotif = new Notification.Builder(this); + } + autoUploadNotif.setContentTitle(getText(R.string.notification_title)) .setContentText(notificationMessage()) .setSmallIcon(R.drawable.ic_stat_notify) .setContentIntent(pendingIntent); diff --git a/clients/android/app/src/main/res/values/strings.xml b/clients/android/app/src/main/res/values/strings.xml index 64f398927..b116648d1 100644 --- a/clients/android/app/src/main/res/values/strings.xml +++ b/clients/android/app/src/main/res/values/strings.xml @@ -37,7 +37,8 @@ Results Required SSID Perkeep auto-uploader - Perkeep channel - Perkeep channel + perkeep auto-upload channel + Auto-upload state + State of Perkeep auto-uploader diff --git a/clients/android/devenv/Dockerfile b/clients/android/devenv/Dockerfile index 158cdf9e5..1c381de6c 100644 --- a/clients/android/devenv/Dockerfile +++ b/clients/android/devenv/Dockerfile @@ -37,9 +37,9 @@ RUN echo y | $ANDROID_HOME/tools/bin/sdkmanager 'ndk-bundle' # Get Go stable release WORKDIR $GOPHER -RUN curl -O https://storage.googleapis.com/golang/go1.9.3.linux-amd64.tar.gz -RUN echo 'a4da5f4c07dfda8194c4621611aeb7ceaab98af0b38bfb29e1be2ebb04c3556c go1.9.3.linux-amd64.tar.gz' | sha256sum -c -RUN tar -xzf go1.9.3.linux-amd64.tar.gz +RUN curl -O https://storage.googleapis.com/golang/go1.11.linux-amd64.tar.gz +RUN echo 'b3fcf280ff86558e0559e185b601c9eade0fd24c900b4c63cd14d1d38613e499 go1.11.linux-amd64.tar.gz' | sha256sum -c +RUN tar -xzf go1.11.linux-amd64.tar.gz ENV GOPATH $GOPHER ENV GOROOT $GOPHER/go ENV PATH $PATH:$GOROOT/bin:$GOPHER/bin