mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-03 09:49:19 +02:00
version for old (2.*) devices does not use google services API
This commit is contained in:
parent
3cdaf8f9fb
commit
28868a7e74
8 changed files with 21 additions and 139 deletions
|
@ -2,8 +2,8 @@
|
||||||
<manifest
|
<manifest
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.geometerplus.zlibrary.ui.android"
|
package="org.geometerplus.zlibrary.ui.android"
|
||||||
android:versionCode="2000510"
|
android:versionCode="2000610"
|
||||||
android:versionName="2.0.5"
|
android:versionName="2.0.6"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
>
|
>
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
@ -330,6 +330,5 @@
|
||||||
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -330,6 +330,5 @@
|
||||||
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.FolderListDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.EditTagsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
<activity android:name="org.geometerplus.android.util.EditAuthorsDialogActivity" android:configChanges="orientation|screenSize|keyboard|keyboardHidden" android:theme="@style/FBReader.Dialog" android:exported="false"/>
|
||||||
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
|
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -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
|
* Fixed possible synchornisation crash
|
||||||
|
|
||||||
===== 2.0.4 (Aug 15, 2014) =====
|
===== 2.0.4 (Aug 15, 2014) =====
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.0.5
|
2.0.6
|
||||||
|
|
|
@ -14,4 +14,3 @@ target=android-14
|
||||||
android.library.reference.1=third-party/AmbilWarna
|
android.library.reference.1=third-party/AmbilWarna
|
||||||
android.library.reference.2=third-party/drag-sort-listview/library
|
android.library.reference.2=third-party/drag-sort-listview/library
|
||||||
android.library.reference.3=third-party/android-filechooser/code
|
android.library.reference.3=third-party/android-filechooser/code
|
||||||
android.library.reference.4=${google.services.lib.dir}
|
|
||||||
|
|
|
@ -28,9 +28,6 @@ import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
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.zlibrary.core.network.*;
|
||||||
import org.geometerplus.android.fbreader.OrientationUtil;
|
import org.geometerplus.android.fbreader.OrientationUtil;
|
||||||
|
@ -98,57 +95,6 @@ public final class ActivityNetworkContext extends AndroidNetworkContext {
|
||||||
return verify(verificationUrl);
|
return verify(verificationUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String,String> 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<String,String> 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<String,String> 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) {
|
private void startActivityAndWait(Intent intent, int requestCode) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
OrientationUtil.startActivityForResult(myActivity, intent, requestCode);
|
OrientationUtil.startActivityForResult(myActivity, intent, requestCode);
|
||||||
|
|
|
@ -26,9 +26,6 @@ import java.util.*;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
||||||
import com.google.android.gms.common.ConnectionResult;
|
|
||||||
import com.google.android.gms.common.GooglePlayServicesUtil;
|
|
||||||
|
|
||||||
import org.geometerplus.zlibrary.core.network.*;
|
import org.geometerplus.zlibrary.core.network.*;
|
||||||
|
|
||||||
public abstract class AndroidNetworkContext extends ZLNetworkContext {
|
public abstract class AndroidNetworkContext extends ZLNetworkContext {
|
||||||
|
@ -37,38 +34,27 @@ public abstract class AndroidNetworkContext extends ZLNetworkContext {
|
||||||
if (!"https".equalsIgnoreCase(uri.getScheme())) {
|
if (!"https".equalsIgnoreCase(uri.getScheme())) {
|
||||||
return Collections.singletonMap("error", "Connection is not secure");
|
return Collections.singletonMap("error", "Connection is not secure");
|
||||||
}
|
}
|
||||||
// TODO: process other codes
|
|
||||||
if (Build.VERSION.SDK_INT >= 14 &&
|
String authUrl = null;
|
||||||
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getContext()) == ConnectionResult.SUCCESS) {
|
final String account = getAccountName(uri.getHost(), realm);
|
||||||
final String authUrl = url(uri, params, "auth-url-token");
|
if (account != null) {
|
||||||
final String clientId = params.get("client-id");
|
final String urlWithAccount = params.get("auth-url-web-with-email");
|
||||||
if (authUrl == null || clientId == null) {
|
if (urlWithAccount != null) {
|
||||||
return errorMap("No data for token authentication");
|
authUrl = url(uri, urlWithAccount.replace("{email}", account));
|
||||||
}
|
}
|
||||||
return authenticateToken(uri, realm, authUrl, clientId);
|
|
||||||
} else {
|
} else {
|
||||||
String authUrl = null;
|
authUrl = url(uri, params, "auth-url-web");
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
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 Context getContext();
|
||||||
protected abstract Map<String,String> authenticateWeb(URI uri, String realm, String authUrl, String completeUrl, String verificationUrl);
|
protected abstract Map<String,String> authenticateWeb(URI uri, String realm, String authUrl, String completeUrl, String verificationUrl);
|
||||||
protected abstract Map<String,String> authenticateToken(URI uri, String realm, String authUrl, String clientId);
|
|
||||||
|
|
||||||
protected Map<String,String> errorMap(String message) {
|
protected Map<String,String> errorMap(String message) {
|
||||||
return Collections.singletonMap("error", message);
|
return Collections.singletonMap("error", message);
|
||||||
|
@ -89,20 +75,6 @@ public abstract class AndroidNetworkContext extends ZLNetworkContext {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Map<String,String> runTokenAuthorization(String authUrl, String authToken, String code) {
|
|
||||||
final Map<String,String> result = new HashMap<String,String>();
|
|
||||||
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<String,String> params, String key) {
|
protected String url(URI base, Map<String,String> params, String key) {
|
||||||
return url(base, params.get(key));
|
return url(base, params.get(key));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,10 +29,6 @@ import android.net.Uri;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.text.TextUtils;
|
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;
|
import org.geometerplus.zlibrary.core.resources.ZLResource;
|
||||||
|
|
||||||
public class ServiceNetworkContext extends AndroidNetworkContext {
|
public class ServiceNetworkContext extends AndroidNetworkContext {
|
||||||
|
@ -72,36 +68,4 @@ public class ServiceNetworkContext extends AndroidNetworkContext {
|
||||||
notificationManager.notify(0, notification);
|
notificationManager.notify(0, notification);
|
||||||
return errorMap("Notification sent");
|
return errorMap("Notification sent");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<String,String> 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<String,String> 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 ---");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue