Replace play services auth library

Google Tasks and Drive support for F-Droid and Amazon builds
pull/820/head
Alex Baker 6 years ago
parent 569f5e57f1
commit f6505cf985

@ -163,7 +163,7 @@ dependencies {
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
//noinspection GradleDependency
implementation 'com.google.guava:guava:20.0'
implementation 'com.google.guava:guava:27.1-android'
implementation 'com.jakewharton:process-phoenix:2.0.0'
implementation 'com.google.android.apps.dashclock:dashclock-api:2.0.0'
implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.2'
@ -178,18 +178,15 @@ dependencies {
implementation 'com.google.apis:google-api-services-tasks:v1-rev55-1.25.0'
implementation 'com.google.apis:google-api-services-drive:v3-rev136-1.25.0'
implementation 'com.google.api-client:google-api-client-android:1.27.0'
implementation("androidx.work:work-runtime:${WORK_VERSION}") {
// https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw
exclude group: 'com.google.guava', module: 'listenablefuture'
}
implementation "androidx.work:work-runtime:${WORK_VERSION}"
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.3.0'
implementation'com.mapbox.mapboxsdk:mapbox-sdk-services:4.5.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:0.15.0'
googleplayImplementation "com.crashlytics.sdk.android:crashlytics:${CRASHLYTICS_VERSION}"
googleplayImplementation "com.google.firebase:firebase-core:${FIREBASE_VERSION}"
googleplayImplementation "com.google.android.gms:play-services-location:16.0.0"
googleplayImplementation 'com.google.android.gms:play-services-maps:16.1.0'
googleplayImplementation "com.google.android.gms:play-services-auth:16.0.1"
googleplayImplementation 'com.google.android.libraries.places:places:1.1.0'
googleplayImplementation 'com.android.billingclient:billing:1.2.1'

@ -670,3 +670,57 @@
copyrightHolder: Square, Inc.
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
- artifact: io.grpc:grpc-context:+
name: io.grpc:grpc-context
copyrightHolder: The gRPC Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/grpc/grpc-java
- artifact: com.google.guava:listenablefuture:+
name: Guava ListenableFuture only
copyrightHolder: The Guava Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
- artifact: org.codehaus.mojo:animal-sniffer-annotations:+
name: Animal Sniffer Annotations
copyrightHolder: codehaus.org
license: MIT License
licenseUrl: http://www.opensource.org/licenses/mit-license.php
- artifact: com.google.errorprone:error_prone_annotations:+
name: error-prone annotations
copyrightHolder: The Error Prone Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
- artifact: com.google.auth:google-auth-library-oauth2-http:+
name: Google Auth Library for Java - OAuth2 HTTP
copyrightHolder: Google Inc.
license: BSD 3-Clause
licenseUrl: https://opensource.org/licenses/BSD-3-Clause
- artifact: io.opencensus:opencensus-api:+
name: OpenCensus API
copyrightHolder: OpenCensus Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/census-instrumentation/opencensus-java
- artifact: com.google.auth:google-auth-library-credentials:+
name: Google Auth Library for Java - Credentials
copyrightHolder: Google Inc.
license: BSD 3-Clause
licenseUrl: https://opensource.org/licenses/BSD-3-Clause
- artifact: com.google.guava:failureaccess:+
name: Guava InternalFutureFailureAccess and InternalFutures
copyrightHolder: The Guava Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
- artifact: org.checkerframework:checker-compat-qual:+
name: Checker Qual
copyrightHolder: The Checker Framework Developers
license: GNU General Public License, Version 2.0 + classpath exception
licenseUrl: http://www.gnu.org/software/classpath/license.html
url: https://checkerframework.org
- artifact: io.opencensus:opencensus-contrib-http-util:+
name: OpenCensus contrib-http-util
copyrightHolder: OpenCensus Authors
license: The Apache Software License, Version 2.0
licenseUrl: http://www.apache.org/licenses/LICENSE-2.0.txt
url: https://github.com/census-instrumentation/opencensus-java

@ -1,24 +0,0 @@
package org.tasks.gtasks;
import android.accounts.Account;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
public class GoogleAccountManager {
@Inject
public GoogleAccountManager() {}
public List<String> getAccounts() {
return Collections.emptyList();
}
private List<Account> getAccountList() {
return Collections.emptyList();
}
public Account getAccount(final String name) {
return null;
}
}

@ -2,12 +2,9 @@ package org.tasks.gtasks;
import android.app.Activity;
import com.todoroo.astrid.activity.MainActivity;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import javax.inject.Inject;
import org.tasks.drive.DriveLoginActivity;
import org.tasks.play.AuthResultHandler;
public class PlayServices {
@ -28,13 +25,7 @@ public class PlayServices {
return null;
}
public void getDriveAuthToken(
DriveLoginActivity driveLoginActivity, String a, AuthResultHandler authResultHandler) {}
public Disposable check(MainActivity mainActivity) {
return Disposables.empty();
}
public void getTasksAuthToken(
GtasksLoginActivity gtasksLoginActivity, String a, AuthResultHandler authResultHandler) {}
}

@ -3,6 +3,7 @@
<string-array name="pro_description">
<item>@string/themes</item>
<item>@string/pro_caldav_sync</item>
<item>@string/pro_multiple_google_task_accounts</item>
<item>@string/pro_tasker_plugins</item>
<item>@string/pro_dashclock_extension</item>
</string-array>

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sku_themes">themes</string>
<string name="common_google_play_services_notification_ticker">Google Play services error</string>
<string name="market_url">amzn://apps/android?p=org.tasks</string>
<string name="p_purchases">purchases_amazon</string>

@ -1,51 +0,0 @@
package org.tasks.injection;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDaoTests;
import com.todoroo.astrid.dao.TaskDaoTests;
import com.todoroo.astrid.model.TaskTest;
import com.todoroo.astrid.provider.Astrid3ProviderTests;
import com.todoroo.astrid.reminders.NotificationTests;
import com.todoroo.astrid.reminders.ReminderServiceTest;
import com.todoroo.astrid.repeats.NewRepeatTests;
import com.todoroo.astrid.service.QuickAddMarkupTest;
import com.todoroo.astrid.service.TitleParserTest;
import com.todoroo.astrid.subtasks.SubtasksHelperTest;
import com.todoroo.astrid.subtasks.SubtasksTestCase;
import com.todoroo.astrid.sync.NewSyncTestCase;
import dagger.Component;
import org.tasks.jobs.BackupServiceTests;
@ApplicationScope
@Component(modules = TestModule.class)
public interface TestComponent {
Database getDatabase();
void inject(ReminderServiceTest reminderServiceTest);
void inject(TaskTest taskTest);
void inject(TaskDaoTests taskDaoTests);
void inject(MetadataDaoTests metadataDaoTests);
void inject(Astrid3ProviderTests astrid3ProviderTests);
void inject(NewSyncTestCase newSyncTestCase);
void inject(SubtasksTestCase subtasksTestCase);
void inject(SubtasksHelperTest subtasksHelperTest);
void inject(QuickAddMarkupTest quickAddMarkupTest);
void inject(TitleParserTest titleParserTest);
void inject(NewRepeatTests newRepeatTests);
void inject(BackupServiceTests backupServiceTests);
NotificationTests.NotificationTestsComponent plus(
NotificationTests.NotificationTestsModule notificationTestsModule);
}

@ -1,51 +0,0 @@
package org.tasks.injection;
import com.todoroo.astrid.dao.Database;
import com.todoroo.astrid.dao.MetadataDaoTests;
import com.todoroo.astrid.dao.TaskDaoTests;
import com.todoroo.astrid.model.TaskTest;
import com.todoroo.astrid.provider.Astrid3ProviderTests;
import com.todoroo.astrid.reminders.NotificationTests;
import com.todoroo.astrid.reminders.ReminderServiceTest;
import com.todoroo.astrid.repeats.NewRepeatTests;
import com.todoroo.astrid.service.QuickAddMarkupTest;
import com.todoroo.astrid.service.TitleParserTest;
import com.todoroo.astrid.subtasks.SubtasksHelperTest;
import com.todoroo.astrid.subtasks.SubtasksTestCase;
import com.todoroo.astrid.sync.NewSyncTestCase;
import dagger.Component;
import org.tasks.jobs.BackupServiceTests;
@ApplicationScope
@Component(modules = TestModule.class)
public interface TestComponent {
Database getDatabase();
void inject(ReminderServiceTest reminderServiceTest);
void inject(TaskTest taskTest);
void inject(TaskDaoTests taskDaoTests);
void inject(MetadataDaoTests metadataDaoTests);
void inject(Astrid3ProviderTests astrid3ProviderTests);
void inject(NewSyncTestCase newSyncTestCase);
void inject(SubtasksTestCase subtasksTestCase);
void inject(SubtasksHelperTest subtasksHelperTest);
void inject(QuickAddMarkupTest quickAddMarkupTest);
void inject(TitleParserTest titleParserTest);
void inject(NewRepeatTests newRepeatTests);
void inject(BackupServiceTests backupServiceTests);
NotificationTests.NotificationTestsComponent plus(
NotificationTests.NotificationTestsModule notificationTestsModule);
}

@ -1,24 +0,0 @@
package org.tasks.gtasks;
import android.accounts.Account;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
public class GoogleAccountManager {
@Inject
public GoogleAccountManager() {}
public List<String> getAccounts() {
return Collections.emptyList();
}
private List<Account> getAccountList() {
return Collections.emptyList();
}
public Account getAccount(final String name) {
return null;
}
}

@ -2,12 +2,9 @@ package org.tasks.gtasks;
import android.app.Activity;
import com.todoroo.astrid.activity.MainActivity;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
import javax.inject.Inject;
import org.tasks.drive.DriveLoginActivity;
import org.tasks.play.AuthResultHandler;
public class PlayServices {
@ -28,12 +25,6 @@ public class PlayServices {
return null;
}
public void getTasksAuthToken(
GtasksLoginActivity gtasksLoginActivity, String a, AuthResultHandler authResultHandler) {}
public void getDriveAuthToken(
DriveLoginActivity driveLoginActivity, String a, AuthResultHandler authResultHandler) {}
public Disposable check(MainActivity mainActivity) {
return Disposables.empty();
}

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="sku_themes">themes</string>
<string name="common_google_play_services_notification_ticker">Google Play services error</string>
<string name="market_url">https://f-droid.org/en/packages/org.tasks/</string>
<string name="p_purchases">purchases_fdroid</string>

@ -3,14 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.tasks">
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- **************** -->
<!-- google task sync -->
<!-- **************** -->
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" android:maxSdkVersion="25"/>
<application tools:ignore="GoogleAppIndexingWarning">
<meta-data
@ -26,16 +18,6 @@
android:value="@integer/google_play_services_version"/>
<service android:name=".location.GeofenceTransitionsIntentService"/>
<activity android:name=".activities.GoogleTaskListSettingsActivity"/>
<activity
android:name="com.todoroo.astrid.gtasks.auth.GtasksLoginActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:name=".drive.DriveLoginActivity"
android:theme="@style/TranslucentDialog" />
</application>
</manifest>

@ -1,46 +0,0 @@
package org.tasks.gtasks;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.transform;
import static java.util.Arrays.asList;
import android.accounts.Account;
import android.content.Context;
import com.google.common.base.Strings;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.PermissionChecker;
public class GoogleAccountManager {
private final PermissionChecker permissionChecker;
private final android.accounts.AccountManager accountManager;
@Inject
public GoogleAccountManager(
@ForApplication Context context, PermissionChecker permissionChecker) {
this.permissionChecker = permissionChecker;
accountManager = android.accounts.AccountManager.get(context);
}
public List<String> getAccounts() {
return transform(getAccountList(), account -> account.name);
}
private List<Account> getAccountList() {
return permissionChecker.canAccessAccounts()
? asList(accountManager.getAccountsByType("com.google"))
: Collections.emptyList();
}
public Account getAccount(final String name) {
if (Strings.isNullOrEmpty(name)) {
return null;
}
return tryFind(getAccountList(), account -> name.equalsIgnoreCase(account.name)).orNull();
}
}

@ -2,29 +2,20 @@ package org.tasks.gtasks;
import static io.reactivex.Single.fromCallable;
import android.accounts.Account;
import android.app.Activity;
import android.content.Context;
import android.widget.Toast;
import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.tasks.TasksScopes;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import java.io.IOException;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.data.LocationDao;
import org.tasks.injection.ForApplication;
import org.tasks.play.AuthResultHandler;
import org.tasks.preferences.Preferences;
import timber.log.Timber;
@ -34,7 +25,6 @@ public class PlayServices {
private final Context context;
private final Preferences preferences;
private final GoogleAccountManager accountManager;
private final GoogleTaskListDao googleTaskListDao;
private final LocationDao locationDao;
@ -42,12 +32,10 @@ public class PlayServices {
public PlayServices(
@ForApplication Context context,
Preferences preferences,
GoogleAccountManager googleAccountManager,
GoogleTaskListDao googleTaskListDao,
LocationDao locationDao) {
this.context = context;
this.preferences = preferences;
this.accountManager = googleAccountManager;
this.googleTaskListDao = googleTaskListDao;
this.locationDao = locationDao;
}
@ -107,38 +95,4 @@ public class PlayServices {
return preferences.getInt(R.string.play_services_available, -1);
}
public void getTasksAuthToken(
final Activity activity, final String accountName, final AuthResultHandler handler) {
getToken(TasksScopes.TASKS, activity, accountName, handler);
}
public void getDriveAuthToken(
final Activity activity, final String accountName, final AuthResultHandler handler) {
getToken(DriveScopes.DRIVE_FILE, activity, accountName, handler);
}
private void getToken(
String scope, Activity activity, String accountName, AuthResultHandler handler) {
final Account account = accountManager.getAccount(accountName);
if (account == null) {
handler.authenticationFailed(
activity.getString(R.string.gtasks_error_accountNotFound, accountName));
} else {
new Thread(
() -> {
try {
GoogleAuthUtil.getToken(activity, account, "oauth2:" + scope, null);
handler.authenticationSuccessful(accountName);
} catch (UserRecoverableAuthException e) {
Timber.e(e);
activity.startActivityForResult(
e.getIntent(), GtasksLoginActivity.RC_REQUEST_OAUTH);
} catch (GoogleAuthException | IOException e) {
Timber.e(e);
handler.authenticationFailed(activity.getString(R.string.gtasks_GLA_errorIOAuth));
}
})
.start();
}
}
}

@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.tasks">
<uses-sdk tools:overrideLibrary="at.bitfire.ical4android"/>
<!-- ================================================== Used Permissions = -->
@ -61,12 +60,20 @@
<!-- *********************************** -->
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<!-- *************************** -->
<!-- caldav and google task sync -->
<!-- *************************** -->
<!-- ****************************************************** -->
<!-- caldav sync, google task sync, and google drive upload -->
<!-- ****************************************************** -->
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- **************************************** -->
<!-- google task sync and google drive upload -->
<!-- **************************************** -->
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="com.google.android.googleapps.permission.GOOGLE_AUTH"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" android:maxSdkVersion="25"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- ============================================== Exported Permissions = -->
<!-- for v2 tasks provider -->
@ -100,7 +107,7 @@
android:roundIcon="@mipmap/ic_launcher_blue"
android:supportsRtl="true"
android:theme="@style/Tasks"
tools:ignore="GoogleAppIndexingWarning">
tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">
<meta-data
android:name="firebase_crashlytics_collection_enabled"
@ -331,6 +338,16 @@
<receiver android:name="com.todoroo.astrid.gcal.CalendarAlarmReceiver"/>
<activity android:name=".activities.GoogleTaskListSettingsActivity"/>
<activity
android:name="com.todoroo.astrid.gtasks.auth.GtasksLoginActivity"
android:theme="@style/TranslucentDialog"/>
<activity
android:name=".drive.DriveLoginActivity"
android:theme="@style/TranslucentDialog" />
<!-- old tasks -->
<activity
android:label="@string/EPr_manage_header"

@ -557,7 +557,7 @@
"artifactId": {
"name": "guava",
"group": "com.google.guava",
"version": "20.0"
"version": "27.1-android"
}
},
{
@ -1549,7 +1549,7 @@
"artifactId": {
"name": "google-http-client",
"group": "com.google.http-client",
"version": "1.27.0"
"version": "1.29.0"
}
},
{
@ -1677,7 +1677,7 @@
"artifactId": {
"name": "google-http-client-jackson2",
"group": "com.google.http-client",
"version": "1.27.0"
"version": "1.29.0"
}
},
{
@ -1791,6 +1791,166 @@
"group": "com.jakewharton",
"version": "2.0.0"
}
},
{
"notice": null,
"copyrightHolder": "The gRPC Authors",
"copyrightStatement": "Copyright &copy; The gRPC Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "https://github.com/grpc/grpc-java",
"libraryName": "io.grpc:grpc-context",
"artifactId": {
"name": "grpc-context",
"group": "io.grpc",
"version": "1.14.0"
}
},
{
"notice": null,
"copyrightHolder": "The Guava Authors",
"copyrightStatement": "Copyright &copy; The Guava Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "",
"libraryName": "Guava ListenableFuture only",
"artifactId": {
"name": "listenablefuture",
"group": "com.google.guava",
"version": "9999.0-empty-to-avoid-conflict-with-guava"
}
},
{
"notice": null,
"copyrightHolder": "codehaus.org",
"copyrightStatement": "Copyright &copy; codehaus.org. All rights reserved.",
"license": "MIT License",
"licenseUrl": "http://www.opensource.org/licenses/mit-license.php",
"normalizedLicense": "mit",
"year": null,
"url": "",
"libraryName": "Animal Sniffer Annotations",
"artifactId": {
"name": "animal-sniffer-annotations",
"group": "org.codehaus.mojo",
"version": "1.17"
}
},
{
"notice": null,
"copyrightHolder": "The Error Prone Authors",
"copyrightStatement": "Copyright &copy; The Error Prone Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "",
"libraryName": "error-prone annotations",
"artifactId": {
"name": "error_prone_annotations",
"group": "com.google.errorprone",
"version": "2.2.0"
}
},
{
"notice": null,
"copyrightHolder": "Google Inc.",
"copyrightStatement": "Copyright &copy; Google Inc. All rights reserved.",
"license": "BSD 3-Clause",
"licenseUrl": "https://opensource.org/licenses/BSD-3-Clause",
"normalizedLicense": "bsd_3_clauses",
"year": null,
"url": "",
"libraryName": "Google Auth Library for Java - OAuth2 HTTP",
"artifactId": {
"name": "google-auth-library-oauth2-http",
"group": "com.google.auth",
"version": "0.15.0"
}
},
{
"notice": null,
"copyrightHolder": "OpenCensus Authors",
"copyrightStatement": "Copyright &copy; OpenCensus Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "https://github.com/census-instrumentation/opencensus-java",
"libraryName": "OpenCensus API",
"artifactId": {
"name": "opencensus-api",
"group": "io.opencensus",
"version": "0.18.0"
}
},
{
"notice": null,
"copyrightHolder": "Google Inc.",
"copyrightStatement": "Copyright &copy; Google Inc. All rights reserved.",
"license": "BSD 3-Clause",
"licenseUrl": "https://opensource.org/licenses/BSD-3-Clause",
"normalizedLicense": "bsd_3_clauses",
"year": null,
"url": "",
"libraryName": "Google Auth Library for Java - Credentials",
"artifactId": {
"name": "google-auth-library-credentials",
"group": "com.google.auth",
"version": "0.15.0"
}
},
{
"notice": null,
"copyrightHolder": "The Guava Authors",
"copyrightStatement": "Copyright &copy; The Guava Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "",
"libraryName": "Guava InternalFutureFailureAccess and InternalFutures",
"artifactId": {
"name": "failureaccess",
"group": "com.google.guava",
"version": "1.0.1"
}
},
{
"notice": null,
"copyrightHolder": "The Checker Framework Developers",
"copyrightStatement": "Copyright &copy; The Checker Framework Developers. All rights reserved.",
"license": "GNU General Public License, Version 2.0 + classpath exception",
"licenseUrl": "http://www.gnu.org/software/classpath/license.html",
"normalizedLicense": "gpl2",
"year": null,
"url": "https://checkerframework.org",
"libraryName": "Checker Qual",
"artifactId": {
"name": "checker-compat-qual",
"group": "org.checkerframework",
"version": "2.5.2"
}
},
{
"notice": null,
"copyrightHolder": "OpenCensus Authors",
"copyrightStatement": "Copyright &copy; OpenCensus Authors. All rights reserved.",
"license": "The Apache Software License, Version 2.0",
"licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0.txt",
"normalizedLicense": "apache2",
"year": null,
"url": "https://github.com/census-instrumentation/opencensus-java",
"libraryName": "OpenCensus contrib-http-util",
"artifactId": {
"name": "opencensus-contrib-http-util",
"group": "io.opencensus",
"version": "0.18.0"
}
}
]
}

@ -1,13 +1,14 @@
package com.todoroo.astrid.gtasks.api;
import android.content.Context;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import android.accounts.AccountManager;
import android.os.Bundle;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.ExponentialBackOff;
import com.google.api.services.tasks.Tasks;
import com.google.api.services.tasks.TasksRequest;
import com.google.api.services.tasks.TasksScopes;
@ -15,8 +16,8 @@ import com.google.api.services.tasks.model.Task;
import com.google.api.services.tasks.model.TaskList;
import com.google.api.services.tasks.model.TaskLists;
import java.io.IOException;
import java.util.Collections;
import org.tasks.BuildConfig;
import org.tasks.gtasks.GoogleAccountManager;
import timber.log.Timber;
/**
@ -27,15 +28,26 @@ import timber.log.Timber;
*/
public class GtasksInvoker {
private final Tasks service;
private final String account;
private final GoogleAccountManager googleAccountManager;
private Tasks service;
private GoogleCredential credential;
public GtasksInvoker(Context context, String account) {
GoogleAccountCredential credential =
GoogleAccountCredential.usingOAuth2(context, Collections.singletonList(TasksScopes.TASKS))
.setBackOff(new ExponentialBackOff.Builder().build())
.setSelectedAccountName(account);
public GtasksInvoker(String account, GoogleAccountManager googleAccountManager) {
this.account = account;
this.googleAccountManager = googleAccountManager;
initializeService();
}
private void initializeService() {
Bundle bundle = googleAccountManager.getAccessToken(account, TasksScopes.TASKS);
String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
credential = new GoogleCredential().setAccessToken(token);
service =
new Tasks.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
new Tasks.Builder(
new NetHttpTransport(),
new JacksonFactory(),
credential)
.setApplicationName(String.format("Tasks/%s", BuildConfig.VERSION_NAME))
.build();
}
@ -103,10 +115,25 @@ public class GtasksInvoker {
}
private synchronized <T> T execute(TasksRequest<T> request) throws IOException {
return execute(request, false);
}
private synchronized <T> T execute(TasksRequest<T> request, boolean retry) throws IOException {
String caller = getCaller();
Timber.d("%s request: %s", caller, request);
HttpRequest httpRequest = request.buildHttpRequest();
HttpResponse httpResponse = httpRequest.execute();
HttpResponse httpResponse;
try {
httpResponse = httpRequest.execute();
} catch (HttpResponseException e) {
if (e.getStatusCode() == 401 && !retry) {
googleAccountManager.invalidateToken(credential.getAccessToken());
initializeService();
return execute(request, true);
} else {
throw e;
}
}
T response = httpResponse.parseAs(request.getResponseClass());
Timber.d("%s response: %s", caller, prettyPrint(response));
return response;

@ -11,13 +11,13 @@ import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.todoroo.andlib.utility.DialogUtilities;
import io.reactivex.disposables.CompositeDisposable;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.gtasks.PlayServices;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.play.AuthResultHandler;
@ -30,13 +30,11 @@ import org.tasks.play.AuthResultHandler;
*/
public class GtasksLoginActivity extends InjectingAppCompatActivity {
public static final int RC_REQUEST_OAUTH = 10987;
private static final int RC_CHOOSE_ACCOUNT = 10988;
@Inject DialogBuilder dialogBuilder;
@Inject GoogleAccountManager accountManager;
@Inject PlayServices playServices;
@Inject GoogleAccountManager googleAccountManager;
@Inject GoogleTaskListDao googleTaskListDao;
private String accountName;
private CompositeDisposable disposables;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -56,53 +54,63 @@ public class GtasksLoginActivity extends InjectingAppCompatActivity {
private void getAuthToken(String account) {
final ProgressDialog pd = dialogBuilder.newProgressDialog(R.string.gtasks_GLA_authenticating);
pd.show();
accountName = account;
getAuthToken(account, pd);
}
@Override
protected void onPause() {
super.onPause();
if (disposables != null) {
disposables.dispose();
}
}
private void getAuthToken(String a, final ProgressDialog pd) {
playServices.getTasksAuthToken(
this,
a,
new AuthResultHandler() {
@Override
public void authenticationSuccessful(String accountName) {
GoogleTaskAccount account = googleTaskListDao.getAccount(accountName);
if (account == null) {
account = new GoogleTaskAccount();
account.setAccount(accountName);
googleTaskListDao.insert(account);
} else {
account.setError("");
googleTaskListDao.update(account);
}
setResult(RESULT_OK);
finish();
DialogUtilities.dismissDialog(GtasksLoginActivity.this, pd);
}
disposables =
new CompositeDisposable(
googleAccountManager.getTasksAuthToken(
this,
a,
new AuthResultHandler() {
@Override
public void authenticationSuccessful(String accountName) {
GoogleTaskAccount account = googleTaskListDao.getAccount(accountName);
if (account == null) {
account = new GoogleTaskAccount();
account.setAccount(accountName);
googleTaskListDao.insert(account);
} else {
account.setError("");
googleTaskListDao.update(account);
}
setResult(RESULT_OK);
finish();
DialogUtilities.dismissDialog(GtasksLoginActivity.this, pd);
}
@Override
public void authenticationFailed(final String message) {
runOnUiThread(
() -> Toast.makeText(GtasksLoginActivity.this, message, Toast.LENGTH_LONG).show());
DialogUtilities.dismissDialog(GtasksLoginActivity.this, pd);
}
});
@Override
public void authenticationFailed(final String message) {
runOnUiThread(
() ->
Toast.makeText(GtasksLoginActivity.this, message, Toast.LENGTH_LONG)
.show());
DialogUtilities.dismissDialog(GtasksLoginActivity.this, pd);
}
}));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_CHOOSE_ACCOUNT && resultCode == RESULT_OK) {
String account = data.getStringExtra(android.accounts.AccountManager.KEY_ACCOUNT_NAME);
getAuthToken(account);
} else if (requestCode == RC_REQUEST_OAUTH && resultCode == RESULT_OK) {
final ProgressDialog pd = dialogBuilder.newProgressDialog(R.string.gtasks_GLA_authenticating);
pd.show();
getAuthToken(accountName, pd);
if (requestCode == RC_CHOOSE_ACCOUNT) {
if (resultCode == RESULT_OK) {
String account = data.getStringExtra(android.accounts.AccountManager.KEY_ACCOUNT_NAME);
getAuthToken(account);
} else {
finish();
}
} else {
// User didn't give permission--cancel
finish();
super.onActivityResult(requestCode, resultCode, data);
}
}
}

@ -6,7 +6,6 @@
package com.todoroo.astrid.gtasks.sync;
import android.content.Context;
import android.text.TextUtils;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
import com.todoroo.andlib.utility.AndroidUtilities;
@ -27,16 +26,15 @@ import org.tasks.data.GoogleTask;
import org.tasks.data.GoogleTaskDao;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.gtasks.GtaskSyncAdapterHelper;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import timber.log.Timber;
@ApplicationScope
public class GtasksSyncService {
private final Context context;
private final TaskDao taskDao;
private final Preferences preferences;
private final LinkedBlockingQueue<SyncOnSaveOperation> operationQueue =
@ -44,22 +42,23 @@ public class GtasksSyncService {
private final GtaskSyncAdapterHelper gtaskSyncAdapterHelper;
private final Tracker tracker;
private final GoogleTaskDao googleTaskDao;
private final GoogleAccountManager googleAccountManager;
@Inject
public GtasksSyncService(
@ForApplication Context context,
TaskDao taskDao,
Preferences preferences,
GtaskSyncAdapterHelper gtaskSyncAdapterHelper,
Tracker tracker,
GoogleTaskDao googleTaskDao,
GoogleTaskListDao googleTaskListDao) {
this.context = context;
GoogleTaskListDao googleTaskListDao,
GoogleAccountManager googleAccountManager) {
this.taskDao = taskDao;
this.preferences = preferences;
this.gtaskSyncAdapterHelper = gtaskSyncAdapterHelper;
this.tracker = tracker;
this.googleTaskDao = googleTaskDao;
this.googleAccountManager = googleAccountManager;
new OperationPushThread(operationQueue).start();
}
@ -169,7 +168,7 @@ public class GtasksSyncService {
@Override
public void op() throws IOException {
GtasksInvoker invoker = new GtasksInvoker(context, googleTaskList.getAccount());
GtasksInvoker invoker = new GtasksInvoker(googleTaskList.getAccount(), googleAccountManager);
pushMetadataOnSave(googleTask, invoker);
}
}

@ -1,13 +1,13 @@
package org.tasks.activities;
import android.content.Context;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.ui.CompletableViewModel;
@SuppressWarnings("WeakerAccess")
public class CreateListViewModel extends CompletableViewModel<TaskList> {
void createList(Context context, String account, String name) {
run(() -> new GtasksInvoker(context, account).createGtaskList(name));
void createList(GoogleAccountManager googleAccountManager, String account, String name) {
run(() -> new GtasksInvoker(account, googleAccountManager).createGtaskList(name));
}
}

@ -1,13 +1,13 @@
package org.tasks.activities;
import android.content.Context;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.data.GoogleTaskList;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.ui.ActionViewModel;
@SuppressWarnings("WeakerAccess")
public class DeleteListViewModel extends ActionViewModel {
void deleteList(Context context, GoogleTaskList list) {
run(() -> new GtasksInvoker(context, list.getAccount()).deleteGtaskList(list.getRemoteId()));
void deleteList(GoogleAccountManager googleAccountManager, GoogleTaskList list) {
run(() -> new GtasksInvoker(list.getAccount(), googleAccountManager).deleteGtaskList(list.getRemoteId()));
}
}

@ -33,6 +33,7 @@ import org.tasks.data.GoogleTaskAccount;
import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
@ -58,6 +59,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi
@Inject ThemeCache themeCache;
@Inject ThemeColor themeColor;
@Inject TaskDeleter taskDeleter;
@Inject GoogleAccountManager googleAccountManager;
@BindView(R.id.name)
TextInputEditText name;
@ -204,10 +206,10 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi
if (isNewList) {
showProgressIndicator();
createListViewModel.createList(context, gtasksList.getAccount(), newName);
createListViewModel.createList(googleAccountManager, gtasksList.getAccount(), newName);
} else if (nameChanged()) {
showProgressIndicator();
renameListViewModel.renameList(context, gtasksList, newName);
renameListViewModel.renameList(googleAccountManager, gtasksList, newName);
} else {
if (colorChanged()) {
gtasksList.setColor(selectedTheme);
@ -248,7 +250,7 @@ public class GoogleTaskListSettingsActivity extends ThemedInjectingAppCompatActi
R.string.delete,
(dialog, which) -> {
showProgressIndicator();
deleteListViewModel.deleteList(context, gtasksList);
deleteListViewModel.deleteList(googleAccountManager, gtasksList);
})
.setNegativeButton(android.R.string.cancel, null)
.show();

@ -1,17 +1,17 @@
package org.tasks.activities;
import android.content.Context;
import com.google.api.services.tasks.model.TaskList;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.data.GoogleTaskList;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.ui.CompletableViewModel;
@SuppressWarnings("WeakerAccess")
public class RenameListViewModel extends CompletableViewModel<TaskList> {
void renameList(Context context, GoogleTaskList list, String name) {
void renameList(GoogleAccountManager googleAccountManager, GoogleTaskList list, String name) {
run(
() ->
new GtasksInvoker(context, list.getAccount())
new GtasksInvoker(list.getAccount(), googleAccountManager)
.renameGtaskList(list.getRemoteId(), name));
}
}

@ -11,11 +11,11 @@ import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;
import com.todoroo.andlib.utility.DialogUtilities;
import io.reactivex.disposables.CompositeDisposable;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.gtasks.PlayServices;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingAppCompatActivity;
import org.tasks.play.AuthResultHandler;
@ -29,13 +29,11 @@ import org.tasks.preferences.Preferences;
*/
public class DriveLoginActivity extends InjectingAppCompatActivity {
public static final int RC_REQUEST_OAUTH = 10987;
private static final int RC_CHOOSE_ACCOUNT = 10988;
@Inject DialogBuilder dialogBuilder;
@Inject GoogleAccountManager accountManager;
@Inject PlayServices playServices;
@Inject GoogleAccountManager googleAccountManager;
@Inject Preferences preferences;
private String accountName;
private CompositeDisposable disposables;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -55,45 +53,55 @@ public class DriveLoginActivity extends InjectingAppCompatActivity {
private void getAuthToken(String account) {
final ProgressDialog pd = dialogBuilder.newProgressDialog(R.string.gtasks_GLA_authenticating);
pd.show();
accountName = account;
getAuthToken(account, pd);
}
@Override
protected void onPause() {
super.onPause();
if (disposables != null) {
disposables.dispose();
}
}
private void getAuthToken(String a, final ProgressDialog pd) {
playServices.getDriveAuthToken(
this,
a,
new AuthResultHandler() {
@Override
public void authenticationSuccessful(String accountName) {
preferences.setString(R.string.p_google_drive_backup_account, accountName);
setResult(RESULT_OK);
finish();
DialogUtilities.dismissDialog(DriveLoginActivity.this, pd);
}
disposables =
new CompositeDisposable(
googleAccountManager.getDriveAuthToken(
this,
a,
new AuthResultHandler() {
@Override
public void authenticationSuccessful(String accountName) {
preferences.setString(R.string.p_google_drive_backup_account, accountName);
setResult(RESULT_OK);
finish();
DialogUtilities.dismissDialog(DriveLoginActivity.this, pd);
}
@Override
public void authenticationFailed(final String message) {
runOnUiThread(
() -> Toast.makeText(DriveLoginActivity.this, message, Toast.LENGTH_LONG).show());
DialogUtilities.dismissDialog(DriveLoginActivity.this, pd);
}
});
@Override
public void authenticationFailed(final String message) {
runOnUiThread(
() ->
Toast.makeText(DriveLoginActivity.this, message, Toast.LENGTH_LONG)
.show());
DialogUtilities.dismissDialog(DriveLoginActivity.this, pd);
}
}));
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_CHOOSE_ACCOUNT && resultCode == RESULT_OK) {
String account = data.getStringExtra(android.accounts.AccountManager.KEY_ACCOUNT_NAME);
getAuthToken(account);
} else if (requestCode == RC_REQUEST_OAUTH && resultCode == RESULT_OK) {
final ProgressDialog pd = dialogBuilder.newProgressDialog(R.string.gtasks_GLA_authenticating);
pd.show();
getAuthToken(accountName, pd);
if (requestCode == RC_CHOOSE_ACCOUNT) {
if (resultCode == RESULT_OK) {
String account = data.getStringExtra(android.accounts.AccountManager.KEY_ACCOUNT_NAME);
getAuthToken(account);
} else {
finish();
}
} else {
// User didn't give permission--cancel
finish();
super.onActivityResult(requestCode, resultCode, data);
}
}
}

@ -0,0 +1,124 @@
package org.tasks.gtasks;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread;
import static java.util.Arrays.asList;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.tasks.TasksScopes;
import com.google.common.base.Strings;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.injection.ForApplication;
import org.tasks.play.AuthResultHandler;
import org.tasks.preferences.PermissionChecker;
import timber.log.Timber;
public class GoogleAccountManager {
private final PermissionChecker permissionChecker;
private final android.accounts.AccountManager accountManager;
@Inject
public GoogleAccountManager(
@ForApplication Context context, PermissionChecker permissionChecker) {
this.permissionChecker = permissionChecker;
accountManager = android.accounts.AccountManager.get(context);
}
public List<String> getAccounts() {
return transform(getAccountList(), account -> account.name);
}
private List<Account> getAccountList() {
return permissionChecker.canAccessAccounts()
? asList(accountManager.getAccountsByType("com.google"))
: Collections.emptyList();
}
public Account getAccount(String name) {
if (Strings.isNullOrEmpty(name)) {
return null;
}
return tryFind(getAccountList(), account -> name.equalsIgnoreCase(account.name)).orNull();
}
public Bundle getAccessToken(String name, String scope) {
assertNotMainThread();
Account account = getAccount(name);
if (account == null) {
Timber.e("Cannot find account %s", name);
return null;
}
try {
return accountManager
.getAuthToken(account, "oauth2:" + scope, new Bundle(), true, null, null)
.getResult();
} catch (AuthenticatorException | IOException | OperationCanceledException e) {
Timber.e(e);
return null;
}
}
public Disposable getTasksAuthToken(
final Activity activity, final String accountName, final AuthResultHandler handler) {
return getToken(TasksScopes.TASKS, activity, accountName, handler);
}
public Disposable getDriveAuthToken(
final Activity activity, final String accountName, final AuthResultHandler handler) {
return getToken(DriveScopes.DRIVE_FILE, activity, accountName, handler);
}
private Disposable getToken(
String scope, Activity activity, String accountName, AuthResultHandler handler) {
final Account account = getAccount(accountName);
return Single.fromCallable(
() -> {
if (account == null) {
throw new RuntimeException(
activity.getString(R.string.gtasks_error_accountNotFound, accountName));
}
assertNotMainThread();
return accountManager
.getAuthToken(account, "oauth2:" + scope, new Bundle(), activity, null, null)
.getResult();
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
bundle -> {
Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
if (intent != null) {
activity.startActivity(intent);
} else {
handler.authenticationSuccessful(accountName);
}
},
e -> handler.authenticationFailed(e.getMessage()));
}
public void invalidateToken(String token) {
accountManager.invalidateAuthToken("com.google", token);
}
}

@ -179,7 +179,7 @@ public class GoogleTaskSynchronizer {
return;
}
GtasksInvoker gtasksInvoker = new GtasksInvoker(context, account.getAccount());
GtasksInvoker gtasksInvoker = new GtasksInvoker(account.getAccount(), googleAccountManager);
pushLocalChanges(account, gtasksInvoker);
List<TaskList> gtaskLists = new ArrayList<>();

@ -5,16 +5,18 @@ import org.tasks.data.GoogleTaskListDao;
public class GtaskSyncAdapterHelper {
private final PlayServices playServices;
private final GoogleTaskListDao googleTaskListDao;
private final GoogleAccountManager googleAccountManager;
@Inject
public GtaskSyncAdapterHelper(PlayServices playServices, GoogleTaskListDao googleTaskListDao) {
this.playServices = playServices;
public GtaskSyncAdapterHelper(
GoogleTaskListDao googleTaskListDao, GoogleAccountManager googleAccountManager) {
this.googleTaskListDao = googleTaskListDao;
this.googleAccountManager = googleAccountManager;
}
public boolean isEnabled() {
return !googleTaskListDao.getAccounts().isEmpty() && playServices.isPlayServicesAvailable();
return !googleTaskListDao.getAccounts().isEmpty()
&& !googleAccountManager.getAccounts().isEmpty();
}
}

@ -3,6 +3,7 @@ package org.tasks.preferences;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybeanMR1;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
import static java.util.Arrays.asList;
import static org.tasks.PermissionUtil.verifyPermissions;
import static org.tasks.dialogs.ExportTasksDialog.newExportTasksDialog;
import static org.tasks.dialogs.ImportTasksDialog.newImportTasksDialog;
import static org.tasks.files.FileHelper.newFilePickerIntent;
@ -19,6 +20,7 @@ import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;
import androidx.annotation.NonNull;
import com.google.common.base.Strings;
import com.todoroo.astrid.core.OldTaskPreferences;
import com.todoroo.astrid.reminders.ReminderPreferences;
@ -75,6 +77,7 @@ public class BasicPreferences extends InjectingPreferenceActivity
@Inject PlayServices playServices;
@Inject Toaster toaster;
@Inject Device device;
@Inject ActivityPermissionRequestor permissionRequestor;
private Bundle result;
@ -183,10 +186,8 @@ public class BasicPreferences extends InjectingPreferenceActivity
}
if ((Boolean) newValue) {
if (playServices.refreshAndCheck()) {
if (permissionRequestor.requestAccountPermissions()) {
requestLogin();
} else {
playServices.resolve(this);
}
return false;
} else {
@ -245,7 +246,6 @@ public class BasicPreferences extends InjectingPreferenceActivity
//noinspection ConstantConditions
if (!BuildConfig.FLAVOR.equals("googleplay")) {
requires(R.string.backup_BPr_header, false, R.string.p_google_drive_backup);
((PreferenceScreen) findPreference(getString(R.string.preference_screen)))
.removePreference(findPreference(getString(R.string.TEA_control_location)));
}
@ -355,6 +355,18 @@ public class BasicPreferences extends InjectingPreferenceActivity
outState.putBundle(EXTRA_RESULT, result);
}
@Override
public void onRequestPermissionsResult(
int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PermissionRequestor.REQUEST_GOOGLE_ACCOUNTS) {
if (verifyPermissions(grantResults)) {
requestLogin();
}
} else {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_THEME_PICKER) {

@ -18,7 +18,6 @@ import androidx.appcompat.app.AlertDialog;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
import com.todoroo.astrid.service.TaskDeleter;
import javax.inject.Inject;
import org.tasks.BuildConfig;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
@ -33,7 +32,6 @@ import org.tasks.data.GoogleTaskListDao;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.GoogleAccountManager;
import org.tasks.gtasks.GtaskSyncAdapterHelper;
import org.tasks.gtasks.PlayServices;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
import org.tasks.jobs.WorkManager;
@ -55,7 +53,6 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
@Inject PermissionChecker permissionChecker;
@Inject Tracker tracker;
@Inject GtaskSyncAdapterHelper gtaskSyncAdapterHelper;
@Inject PlayServices playServices;
@Inject DialogBuilder dialogBuilder;
@Inject SyncAdapters syncAdapters;
@Inject GoogleTaskDao googleTaskDao;
@ -72,10 +69,6 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
super.onCreate(savedInstanceState);
setTitle(R.string.synchronization);
//noinspection ConstantConditions
if (BuildConfig.FLAVOR.equals("googleplay")) {
addPreferencesFromResource(R.xml.preferences_google_tasks);
}
addPreferencesFromResource(R.xml.preferences_synchronization);
@ -119,11 +112,7 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
protected void onResume() {
super.onResume();
//noinspection ConstantConditions
if (BuildConfig.FLAVOR.equals("googleplay")) {
addGoogleTasksAccounts();
}
addGoogleTasksAccounts();
addCaldavAccounts();
}
@ -177,9 +166,7 @@ public class SynchronizationPreferences extends InjectingPreferenceActivity {
}
private void addGoogleTaskAccount() {
if (!playServices.refreshAndCheck()) {
playServices.resolve(this);
} else if (permissionRequestor.requestAccountPermissions()) {
if (permissionRequestor.requestAccountPermissions()) {
requestLogin();
}
}

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
** Copyright (c) 2012 Todoroo Inc
**
** See the file "LICENSE" for the full license governing this code.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="@string/gtasks_GPr_header"
android:title="@string/gtasks_GPr_header"/>
</PreferenceScreen>

@ -5,6 +5,10 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="@string/gtasks_GPr_header"
android:title="@string/gtasks_GPr_header"/>
<PreferenceCategory
android:key="@string/CalDAV"
android:title="@string/CalDAV"/>

Loading…
Cancel
Save