From 354bdb31730f8b30c2491fd45cb0936284ff62de Mon Sep 17 00:00:00 2001 From: mar-v-in Date: Tue, 10 Mar 2015 00:07:50 +0100 Subject: [PATCH] Update for new auth manager --- AndroidManifest.xml | 2 +- protos-repo/auth.proto | 17 ++ .../org/microg/gms/auth/ConsentData.java | 243 ++++++++++++++++++ res/values/permissions.xml | 2 +- .../microg/gms/checkin/CheckinManager.java | 3 +- src/org/microg/gms/people/PeopleManager.java | 22 +- 6 files changed, 268 insertions(+), 21 deletions(-) create mode 100644 protos-repo/auth.proto create mode 100644 protos-src/org/microg/gms/auth/ConsentData.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1d05d5c9..2a424d9d 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -18,7 +18,7 @@ xmlns:tools="http://schemas.android.com/tools" package="com.google.android.gms" android:versionName="1.0" - android:versionCode="6599436"> + android:versionCode="6772000"> DEFAULT_SCOPES = Collections.emptyList(); + + @ProtoField(tag = 1) + public final AppDetails app; + + @ProtoField(tag = 2, label = REPEATED, messageType = ScopeDetails.class) + public final List scopes; + + public ConsentData(AppDetails app, List scopes) { + this.app = app; + this.scopes = immutableCopyOf(scopes); + } + + private ConsentData(Builder builder) { + this(builder.app, builder.scopes); + setBuilder(builder); + } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (!(other instanceof ConsentData)) return false; + ConsentData o = (ConsentData) other; + return equals(app, o.app) + && equals(scopes, o.scopes); + } + + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = app != null ? app.hashCode() : 0; + result = result * 37 + (scopes != null ? scopes.hashCode() : 1); + hashCode = result; + } + return result; + } + + public static final class Builder extends Message.Builder { + + public AppDetails app; + public List scopes; + + public Builder() { + } + + public Builder(ConsentData message) { + super(message); + if (message == null) return; + this.app = message.app; + this.scopes = copyOf(message.scopes); + } + + public Builder app(AppDetails app) { + this.app = app; + return this; + } + + public Builder scopes(List scopes) { + this.scopes = checkForNulls(scopes); + return this; + } + + @Override + public ConsentData build() { + return new ConsentData(this); + } + } + + public static final class AppDetails extends Message { + + public static final String DEFAULT_TITLE = ""; + public static final String DEFAULT_EMAIL = ""; + + @ProtoField(tag = 1, type = STRING) + public final String title; + + @ProtoField(tag = 3, type = STRING) + public final String email; + + public AppDetails(String title, String email) { + this.title = title; + this.email = email; + } + + private AppDetails(Builder builder) { + this(builder.title, builder.email); + setBuilder(builder); + } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (!(other instanceof AppDetails)) return false; + AppDetails o = (AppDetails) other; + return equals(title, o.title) + && equals(email, o.email); + } + + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = title != null ? title.hashCode() : 0; + result = result * 37 + (email != null ? email.hashCode() : 0); + hashCode = result; + } + return result; + } + + public static final class Builder extends Message.Builder { + + public String title; + public String email; + + public Builder() { + } + + public Builder(AppDetails message) { + super(message); + if (message == null) return; + this.title = message.title; + this.email = message.email; + } + + public Builder title(String title) { + this.title = title; + return this; + } + + public Builder email(String email) { + this.email = email; + return this; + } + + @Override + public AppDetails build() { + return new AppDetails(this); + } + } + } + + public static final class ScopeDetails extends Message { + + public static final String DEFAULT_TITLE = ""; + public static final String DEFAULT_DESCRIPTION = ""; + public static final String DEFAULT_ID = ""; + + @ProtoField(tag = 1, type = STRING) + public final String title; + + @ProtoField(tag = 2, type = STRING) + public final String description; + + @ProtoField(tag = 6, type = STRING) + public final String id; + + public ScopeDetails(String title, String description, String id) { + this.title = title; + this.description = description; + this.id = id; + } + + private ScopeDetails(Builder builder) { + this(builder.title, builder.description, builder.id); + setBuilder(builder); + } + + @Override + public boolean equals(Object other) { + if (other == this) return true; + if (!(other instanceof ScopeDetails)) return false; + ScopeDetails o = (ScopeDetails) other; + return equals(title, o.title) + && equals(description, o.description) + && equals(id, o.id); + } + + @Override + public int hashCode() { + int result = hashCode; + if (result == 0) { + result = title != null ? title.hashCode() : 0; + result = result * 37 + (description != null ? description.hashCode() : 0); + result = result * 37 + (id != null ? id.hashCode() : 0); + hashCode = result; + } + return result; + } + + public static final class Builder extends Message.Builder { + + public String title; + public String description; + public String id; + + public Builder() { + } + + public Builder(ScopeDetails message) { + super(message); + if (message == null) return; + this.title = message.title; + this.description = message.description; + this.id = message.id; + } + + public Builder title(String title) { + this.title = title; + return this; + } + + public Builder description(String description) { + this.description = description; + return this; + } + + public Builder id(String id) { + this.id = id; + return this; + } + + @Override + public ScopeDetails build() { + return new ScopeDetails(this); + } + } + } +} diff --git a/res/values/permissions.xml b/res/values/permissions.xml index 426998ed..f255fc9c 100644 --- a/res/values/permissions.xml +++ b/res/values/permissions.xml @@ -150,7 +150,7 @@ Manage your city-level location provides read and write access to the user\'s Maps Engine data from your application. provides read-only access to the user\'s Maps Engine data from your - Full access to your Google Maps account + View and manage your Google Maps for mobile experience Manage your Orkut activity View your Orkut data Know your name, basic info, and list of people you\'re connected to on Google+ diff --git a/src/org/microg/gms/checkin/CheckinManager.java b/src/org/microg/gms/checkin/CheckinManager.java index 54684da7..dbed6734 100644 --- a/src/org/microg/gms/checkin/CheckinManager.java +++ b/src/org/microg/gms/checkin/CheckinManager.java @@ -43,8 +43,7 @@ public class CheckinManager { List accounts = new ArrayList<>(); AccountManager accountManager = AccountManager.get(context); for (Account account : accountManager.getAccountsByType("com.google")) { - String token = AuthManager.getToken(context, account, Constants.GMS_PACKAGE_NAME, - Constants.GMS_PACKAGE_SIGNATURE_SHA1, "ac2dm"); + String token = new AuthManager(context, account.name, Constants.GMS_PACKAGE_NAME, "ac2dm").getAuthToken(); accounts.add(new CheckinClient.Account(account.name, token)); } CheckinRequest request = diff --git a/src/org/microg/gms/people/PeopleManager.java b/src/org/microg/gms/people/PeopleManager.java index a0c5fd6b..e8f82737 100644 --- a/src/org/microg/gms/people/PeopleManager.java +++ b/src/org/microg/gms/people/PeopleManager.java @@ -91,28 +91,16 @@ public class PeopleManager { } } - public static AuthRequest getUserInfoAuthKeyRequest(Context context, Account account) { - return new AuthRequest().fromContext(context) - .appIsGms().callerIsGms() - .service(USERINFO_SCOPE) - .email(account.name) - .token(AccountManager.get(context).getPassword(account)) - .systemPartition() - .hasPermission() - .getAccountId(); - } - public static String getUserInfoAuthKey(Context context, Account account) { - String result = AuthManager.getToken(context, account, Constants.GMS_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1, - USERINFO_SCOPE); + AuthManager authManager = new AuthManager(context, account.name, Constants.GMS_PACKAGE_NAME, USERINFO_SCOPE); + authManager.setPermitted(true); + String result = authManager.getAuthToken(); if (result == null) { try { - AuthResponse response = getUserInfoAuthKeyRequest(context, account).getResponse(); - AuthManager.storeResponse(context, account, - Constants.GMS_PACKAGE_NAME, Constants.GMS_PACKAGE_SIGNATURE_SHA1, - USERINFO_SCOPE, response); + AuthResponse response = authManager.requestAuth(false); result = response.auth; } catch (IOException e) { + Log.w(TAG, e); return null; } }