Merge pull request #41 from grote/android-10

Make app work for Android 10
This commit is contained in:
Steve Soltys 2019-09-22 22:01:18 -04:00 committed by GitHub
commit 6eb6f64696
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 34 additions and 22 deletions

View file

@ -1,9 +1,13 @@
dist: trusty dist: trusty
jdk:
- openjdk11
language: android language: android
android: android:
components: components:
- build-tools-28.0.3 - build-tools-29.0.2
- android-28 - android-29
licenses: licenses:
- android-sdk-license-.+ - android-sdk-license-.+

View file

@ -6,12 +6,12 @@ apply plugin: 'kotlin-android-extensions'
android { android {
compileSdkVersion 28 compileSdkVersion 29
buildToolsVersion '28.0.3' buildToolsVersion '29.0.2'
defaultConfig { defaultConfig {
minSdkVersion 26 minSdkVersion 29
targetSdkVersion 28 targetSdkVersion 29
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -67,6 +67,9 @@ android {
gradle.projectsEvaluated { gradle.projectsEvaluated {
tasks.withType(JavaCompile) { tasks.withType(JavaCompile) {
if (JavaVersion.current() >= JavaVersion.VERSION_1_9) {
options.compilerArgs.addAll(['--release', '8'])
}
options.compilerArgs.add('-Xbootclasspath/p:app/libs/android.jar:app/libs/libcore.jar') options.compilerArgs.add('-Xbootclasspath/p:app/libs/android.jar:app/libs/libcore.jar')
} }
} }
@ -81,6 +84,7 @@ preBuild.doLast {
parsedXml.component[1].remove(jdkNode) parsedXml.component[1].remove(jdkNode)
def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform" def sdkString = "Android API " + android.compileSdkVersion.substring("android-".length()) + " Platform"
//noinspection GroovyResultOfObjectAllocationIgnored // the note gets inserted
new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK']) new Node(parsedXml.component[1], 'orderEntry', ['type': 'jdk', 'jdkName': sdkString, 'jdkType': 'Android SDK'])
XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile)) XmlUtil.serialize(parsedXml, new FileOutputStream(imlFile))
@ -101,7 +105,7 @@ def aospDeps = fileTree(include: [
dependencies { dependencies {
compileOnly aospDeps compileOnly aospDeps
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'commons-io:commons-io:2.6' implementation 'commons-io:commons-io:2.6'
implementation 'io.github.novacrypto:BIP39:2019.01.27' implementation 'io.github.novacrypto:BIP39:2019.01.27'
@ -115,9 +119,9 @@ dependencies {
lintChecks 'com.github.thirdegg:lint-rules:0.0.4-alpha' lintChecks 'com.github.thirdegg:lint-rules:0.0.4-alpha'
testImplementation aospDeps testImplementation aospDeps
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.2'
testImplementation 'io.mockk:mockk:1.9.3' testImplementation 'io.mockk:mockk:1.9.3'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.0' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.5.2'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0' androidTestImplementation 'androidx.test:rules:1.2.0'

Binary file not shown.

Binary file not shown.

View file

@ -5,11 +5,6 @@
android:versionCode="5" android:versionCode="5"
android:versionName="0.3.0"> android:versionName="0.3.0">
<uses-sdk
android:minSdkVersion="26"
android:targetSdkVersion="28"
tools:ignore="GradleOverrides,OldTargetApi" />
<uses-permission <uses-permission
android:name="android.permission.BACKUP" android:name="android.permission.BACKUP"
tools:ignore="ProtectedPermissions" /> tools:ignore="ProtectedPermissions" />

View file

@ -4,6 +4,7 @@ import android.app.Application
import android.app.backup.IRestoreObserver import android.app.backup.IRestoreObserver
import android.app.backup.IRestoreSession import android.app.backup.IRestoreSession
import android.app.backup.RestoreSet import android.app.backup.RestoreSet
import android.os.UserHandle
import android.util.Log import android.util.Log
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
@ -40,7 +41,7 @@ class RestoreViewModel(app: Application) : RequireProvisioningViewModel(app), Re
internal val restoreFinished: LiveData<Int> get() = mRestoreFinished internal val restoreFinished: LiveData<Int> get() = mRestoreFinished
internal fun loadRestoreSets() { internal fun loadRestoreSets() {
val session = this.session ?: backupManager.beginRestoreSession(null, TRANSPORT_ID) val session = this.session ?: backupManager.beginRestoreSessionForUser(UserHandle.myUserId(), null, TRANSPORT_ID)
this.session = session this.session = session
if (session == null) { if (session == null) {

View file

@ -43,7 +43,7 @@ class PackageService {
Log.d(TAG, "Got ${packageList.size} packages: $packageList") Log.d(TAG, "Got ${packageList.size} packages: $packageList")
// TODO why is this filtering out so much? // TODO why is this filtering out so much?
val eligibleApps = backupManager.filterAppsEligibleForBackup(packageList.toTypedArray()) val eligibleApps = backupManager.filterAppsEligibleForBackupForUser(UserHandle.myUserId(), packageList.toTypedArray())
Log.d(TAG, "Filtering left ${eligibleApps.size} eligible packages: ${Arrays.toString(eligibleApps)}") Log.d(TAG, "Filtering left ${eligibleApps.size} eligible packages: ${Arrays.toString(eligibleApps)}")

View file

@ -1,7 +1,12 @@
package com.stevesoltys.backup.session.restore; package com.stevesoltys.backup.session.restore;
import android.app.backup.*; import android.app.backup.BackupManager;
import android.app.backup.IBackupManager;
import android.app.backup.IRestoreObserver;
import android.app.backup.IRestoreSession;
import android.app.backup.RestoreSet;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle;
import java.util.Set; import java.util.Set;
@ -31,7 +36,7 @@ public class RestoreSession extends IRestoreObserver.Stub {
return; return;
} }
restoreSession = backupManager.beginRestoreSession(null, null); restoreSession = backupManager.beginRestoreSessionForUser(UserHandle.myUserId(), null, null);
if (restoreSession == null) { if (restoreSession == null) {
stop(RestoreResult.FAILURE); stop(RestoreResult.FAILURE);
@ -62,7 +67,7 @@ public class RestoreSession extends IRestoreObserver.Stub {
if (restoreSets.length > 0) { if (restoreSets.length > 0) {
RestoreSet restoreSet = restoreSets[0]; RestoreSet restoreSet = restoreSets[0];
String[] packageArray = packages.toArray(new String[0]); String[] packageArray = packages.toArray(new String[0]);
int result = restoreSession.restoreSome(restoreSet.token, this, null, packageArray); int result = restoreSession.restorePackages(restoreSet.token, this, packageArray, null);
if (result != BackupManager.SUCCESS) { if (result != BackupManager.SUCCESS) {
stop(RestoreResult.FAILURE); stop(RestoreResult.FAILURE);

View file

@ -100,7 +100,7 @@ class DocumentsStorage(private val context: Context, storage: Storage?, token: L
@Throws(IOException::class) @Throws(IOException::class)
fun getOutputStream(file: DocumentFile): OutputStream { fun getOutputStream(file: DocumentFile): OutputStream {
return context.contentResolver.openOutputStream(file.uri) ?: throw IOException() return context.contentResolver.openOutputStream(file.uri, "wt") ?: throw IOException()
} }
} }

View file

@ -1,9 +1,12 @@
package com.stevesoltys.backup.ui.storage package com.stevesoltys.backup.ui.storage
import android.app.ActivityManager
import android.app.Application import android.app.Application
import android.app.backup.BackupProgress import android.app.backup.BackupProgress
import android.app.backup.IBackupObserver import android.app.backup.IBackupObserver
import android.net.Uri import android.net.Uri
import android.os.UserHandle
import android.os.UserManager
import android.util.Log import android.util.Log
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import com.stevesoltys.backup.Backup import com.stevesoltys.backup.Backup
@ -25,7 +28,7 @@ internal class BackupStorageViewModel(private val app: Application) : StorageVie
// initialize the new location // initialize the new location
val observer = InitializationObserver() val observer = InitializationObserver()
Backup.backupManager.initializeTransports(arrayOf(TRANSPORT_ID), observer) Backup.backupManager.initializeTransportsForUser(UserHandle.myUserId(), arrayOf(TRANSPORT_ID), observer)
} }
@WorkerThread @WorkerThread

View file

@ -10,7 +10,7 @@ buildscript {
} }
dependencies { dependencies {
// newer versions require us to remove targetSdkVersion from Manifest // newer versions require us to remove targetSdkVersion from Manifest
classpath 'com.android.tools.build:gradle:3.1.0' classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong