diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 62a36d273..cfe80fbc7 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -2,8 +2,8 @@ - diff --git a/AndroidManifest.xml.pattern b/AndroidManifest.xml.pattern index 5f1beda8f..7930568be 100644 --- a/AndroidManifest.xml.pattern +++ b/AndroidManifest.xml.pattern @@ -330,6 +330,5 @@ - diff --git a/ChangeLog b/ChangeLog index 52070e37e..aa8968ed7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -===== 2.0.5 (Aug ??, 2014) ===== +===== 2.0.6 (Aug ??, 2014) ===== +* Version for old (2.*) devices does not use google services API + +===== 2.0.5 (Aug 18, 2014) ===== * Fixed possible synchornisation crash ===== 2.0.4 (Aug 15, 2014) ===== diff --git a/VERSION b/VERSION index e01025862..157e54f3e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.5 +2.0.6 diff --git a/project.properties b/project.properties index 98eab13a4..41cfa65aa 100644 --- a/project.properties +++ b/project.properties @@ -14,4 +14,3 @@ target=android-14 android.library.reference.1=third-party/AmbilWarna android.library.reference.2=third-party/drag-sort-listview/library android.library.reference.3=third-party/android-filechooser/code -android.library.reference.4=${google.services.lib.dir} diff --git a/src/org/geometerplus/android/fbreader/network/auth/ActivityNetworkContext.java b/src/org/geometerplus/android/fbreader/network/auth/ActivityNetworkContext.java index b77fca456..cf44f8866 100644 --- a/src/org/geometerplus/android/fbreader/network/auth/ActivityNetworkContext.java +++ b/src/org/geometerplus/android/fbreader/network/auth/ActivityNetworkContext.java @@ -28,9 +28,6 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.text.TextUtils; -import com.google.android.gms.auth.GoogleAuthUtil; -import com.google.android.gms.auth.UserRecoverableAuthException; -import com.google.android.gms.common.*; import org.geometerplus.zlibrary.core.network.*; import org.geometerplus.android.fbreader.OrientationUtil; @@ -98,57 +95,6 @@ public final class ActivityNetworkContext extends AndroidNetworkContext { return verify(verificationUrl); } - private Map registerAccessToken(String account, String clientId, String authUrl, String authToken) { - String code = null; - try { - code = GoogleAuthUtil.getToken(myActivity, account, String.format( - "oauth2:server:client_id:%s:api_scope:%s", clientId, - TextUtils.join(" ", new Object[] { Scopes.DRIVE_FILE, Scopes.PROFILE }) - ), null); - return runTokenAuthorization(authUrl, authToken, code); - } catch (UserRecoverableAuthException e) { - myAuthorizationConfirmed = false; - startActivityAndWait(e.getIntent(), NetworkLibraryActivity.REQUEST_AUTHORISATION); - if (myAuthorizationConfirmed) { - return registerAccessToken(account, clientId, authUrl, authToken); - } else { - return errorMap("Authorization failed"); - } - } catch (Exception e) { - return errorMap(e); - } - } - - @Override - protected Map authenticateToken(URI uri, String realm, String authUrl, String clientId) { - System.err.println("+++ TOKEN AUTH +++"); - try { - String account = getAccountName(uri.getHost(), realm); - if (account == null) { - final Intent intent = AccountManager.newChooseAccountIntent( - null, null, new String[] { "com.google" }, false, null, null, null, null - ); - startActivityAndWait(intent, NetworkLibraryActivity.REQUEST_ACCOUNT_PICKER); - account = myAccountName; - } - if (account == null) { - return errorMap("No selected account"); - } - final String authToken = GoogleAuthUtil.getToken( - myActivity, account, String.format("audience:server:client_id:%s", clientId) - ); - final Map result = runTokenAuthorization(authUrl, authToken, null); - if (result.containsKey("user")) { - return result; - } - return registerAccessToken(account, clientId, authUrl, authToken); - } catch (Exception e) { - return errorMap(e); - } finally { - System.err.println("--- TOKEN AUTH ---"); - } - } - private void startActivityAndWait(Intent intent, int requestCode) { synchronized (this) { OrientationUtil.startActivityForResult(myActivity, intent, requestCode); diff --git a/src/org/geometerplus/android/fbreader/network/auth/AndroidNetworkContext.java b/src/org/geometerplus/android/fbreader/network/auth/AndroidNetworkContext.java index da9c9c567..c06cbf190 100644 --- a/src/org/geometerplus/android/fbreader/network/auth/AndroidNetworkContext.java +++ b/src/org/geometerplus/android/fbreader/network/auth/AndroidNetworkContext.java @@ -26,9 +26,6 @@ import java.util.*; import android.content.Context; import android.os.Build; -import com.google.android.gms.common.ConnectionResult; -import com.google.android.gms.common.GooglePlayServicesUtil; - import org.geometerplus.zlibrary.core.network.*; public abstract class AndroidNetworkContext extends ZLNetworkContext { @@ -37,38 +34,27 @@ public abstract class AndroidNetworkContext extends ZLNetworkContext { if (!"https".equalsIgnoreCase(uri.getScheme())) { return Collections.singletonMap("error", "Connection is not secure"); } - // TODO: process other codes - if (Build.VERSION.SDK_INT >= 14 && - GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext()) == ConnectionResult.SUCCESS) { - final String authUrl = url(uri, params, "auth-url-token"); - final String clientId = params.get("client-id"); - if (authUrl == null || clientId == null) { - return errorMap("No data for token authentication"); + + String authUrl = null; + final String account = getAccountName(uri.getHost(), realm); + if (account != null) { + final String urlWithAccount = params.get("auth-url-web-with-email"); + if (urlWithAccount != null) { + authUrl = url(uri, urlWithAccount.replace("{email}", account)); } - return authenticateToken(uri, realm, authUrl, clientId); } else { - String authUrl = null; - final String account = getAccountName(uri.getHost(), realm); - if (account != null) { - final String urlWithAccount = params.get("auth-url-web-with-email"); - if (urlWithAccount != null) { - authUrl = url(uri, urlWithAccount.replace("{email}", account)); - } - } else { - authUrl = url(uri, params, "auth-url-web"); - } - final String completeUrl = url(uri, params, "complete-url-web"); - final String verificationUrl = url(uri, params, "verification-url"); - if (authUrl == null || completeUrl == null || verificationUrl == null) { - return errorMap("No data for web authentication"); - } - return authenticateWeb(uri, realm, authUrl, completeUrl, verificationUrl); + authUrl = url(uri, params, "auth-url-web"); } + final String completeUrl = url(uri, params, "complete-url-web"); + final String verificationUrl = url(uri, params, "verification-url"); + if (authUrl == null || completeUrl == null || verificationUrl == null) { + return errorMap("No data for web authentication"); + } + return authenticateWeb(uri, realm, authUrl, completeUrl, verificationUrl); } protected abstract Context getContext(); protected abstract Map authenticateWeb(URI uri, String realm, String authUrl, String completeUrl, String verificationUrl); - protected abstract Map authenticateToken(URI uri, String realm, String authUrl, String clientId); protected Map errorMap(String message) { return Collections.singletonMap("error", message); @@ -89,20 +75,6 @@ public abstract class AndroidNetworkContext extends ZLNetworkContext { return result; } - protected Map runTokenAuthorization(String authUrl, String authToken, String code) { - final Map result = new HashMap(); - final JsonRequest request = new JsonRequest(authUrl) { - public void processResponse(Object response) { - result.putAll((Map)response); - } - }; - request.addPostParameter("auth", authToken); - request.addPostParameter("code", code); - performQuietly(request); - System.err.println("AUTHORIZATION RESULT = " + result); - return result; - } - protected String url(URI base, Map params, String key) { return url(base, params.get(key)); } diff --git a/src/org/geometerplus/android/fbreader/network/auth/ServiceNetworkContext.java b/src/org/geometerplus/android/fbreader/network/auth/ServiceNetworkContext.java index 90cdda42f..d2c2ae236 100644 --- a/src/org/geometerplus/android/fbreader/network/auth/ServiceNetworkContext.java +++ b/src/org/geometerplus/android/fbreader/network/auth/ServiceNetworkContext.java @@ -29,10 +29,6 @@ import android.net.Uri; import android.support.v4.app.NotificationCompat; import android.text.TextUtils; -import com.google.android.gms.auth.GoogleAuthUtil; -import com.google.android.gms.auth.UserRecoverableNotifiedException; -import com.google.android.gms.common.Scopes; - import org.geometerplus.zlibrary.core.resources.ZLResource; public class ServiceNetworkContext extends AndroidNetworkContext { @@ -72,36 +68,4 @@ public class ServiceNetworkContext extends AndroidNetworkContext { notificationManager.notify(0, notification); return errorMap("Notification sent"); } - - @Override - protected Map authenticateToken(URI uri, String realm, String authUrl, String clientId) { - final String account = getAccountName(uri.getHost(), realm); - if (account == null) { - return errorMap("Account name is not specified"); - } - - System.err.println("+++ SERVICE TOKEN AUTH +++"); - try { - final String authToken = GoogleAuthUtil.getTokenWithNotification( - myService, account, String.format("audience:server:client_id:%s", clientId), null - ); - final Map result = runTokenAuthorization(authUrl, authToken, null); - if (result.containsKey("user")) { - return result; - } - final String code = GoogleAuthUtil.getTokenWithNotification( - myService, account, String.format( - "oauth2:server:client_id:%s:api_scope:%s", clientId, - TextUtils.join(" ", new Object[] { Scopes.DRIVE_FILE, Scopes.PROFILE }) - ), null - ); - return runTokenAuthorization(authUrl, authToken, code); - } catch (UserRecoverableNotifiedException e) { - return errorMap(e); - } catch (Exception e) { - return errorMap(e); - } finally { - System.err.println("--- SERVICE TOKEN AUTH ---"); - } - } }