Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private IntentData(Intent intent) {
try {
consentData = ConsentData.ADAPTER.decode(intent.getByteArrayExtra(EXTRA_CONSENT_DATA));
} catch (Exception e) {
// Ignore
Log.w(TAG, "ConsentData decode failed", e);
}
}
}
Expand Down Expand Up @@ -169,24 +169,34 @@ public void onAllow() {
findViewById(R.id.progress_bar).setVisibility(VISIBLE);
findViewById(R.id.no_progress_bar).setVisibility(GONE);
new Thread(() -> {
Bundle result = null;
try {
AuthResponse response = authManager.requestAuthWithBackgroundResolution(data.fromAccountManager);
Bundle result = new Bundle();
result = new Bundle();
result.putString(KEY_AUTHTOKEN, response.auth);
result.putString(KEY_ACCOUNT_NAME, data.accountName);
result.putString(KEY_ACCOUNT_TYPE, data.accountType);
result.putString(KEY_ANDROID_PACKAGE_NAME, data.packageName);
result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
setAccountAuthenticatorResult(result);
} catch (IOException e) {
Log.w(TAG, e);
}
finish();
final Bundle finalResult = result;
runOnUiThread(() -> {
Intent resultIntent = new Intent();
if (finalResult != null) {
setAccountAuthenticatorResult(finalResult);
resultIntent.putExtras(finalResult);
}
setResult(RESULT_OK, resultIntent);
finish();
});
}).start();
}

public void onDeny() {
authManager.setPermitted(false);
setResult(RESULT_CANCELED);
finish();
}

Expand All @@ -204,12 +214,9 @@ private boolean isOAuth() {
}

private String getScopeLabel(String scope) {
if (data.consentData != null) {
for (ConsentData.ScopeDetails scopeDetails : data.consentData.scopes) {
if (scope.equals(scopeDetails.id)) {
return scopeDetails.title;
}
}
ConsentData.ScopeDetails matched = findScopeDetails(scope);
if (matched != null && matched.title != null) {
return matched.title;
}
String labelResourceId = "permission_scope_";
String escapedScope = scope.replace("/", "_").replace("-", "_");
Expand All @@ -226,16 +233,31 @@ private String getScopeLabel(String scope) {
}

private String getScopeDescription(String scope) {
if (data.consentData != null) {
for (ConsentData.ScopeDetails scopeDetails : data.consentData.scopes) {
if (scope.equals(scopeDetails.id)) {
return scopeDetails.description;
}
}
ConsentData.ScopeDetails matched = findScopeDetails(scope);
return matched != null ? matched.description : null;
}

private ConsentData.ScopeDetails findScopeDetails(String scope) {
if (data.consentData == null || scope == null) return null;
String aliasFull = canonicalOidcScope(scope);
for (ConsentData.ScopeDetails sd : data.consentData.scopes) {
if (scope.equals(sd.id)) return sd;
if (aliasFull != null && aliasFull.equals(sd.id)) return sd;
}
return null;
}

private static String canonicalOidcScope(String scope) {
switch (scope) {
case "email":
return "https://www.googleapis.com/auth/userinfo.email";
case "profile":
return "https://www.googleapis.com/auth/userinfo.profile";
default:
return null;
}
}

private String getServiceLabel(String service) {
int labelResource = getResources().getIdentifier("permission_service_" + service + "_label", "string", getPackageName());
if (labelResource != 0) {
Expand Down
8 changes: 4 additions & 4 deletions play-services-core/src/main/res/layout/ask_permission.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:gravity="center_horizontal"
android:paddingTop="10dp"
android:text="@string/account_manager_title"
android:textColor="?attr/colorPrimary"
android:textColor="?android:attr/textColorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Expand Down Expand Up @@ -88,7 +88,7 @@
android:padding="15dp"
android:gravity="center_horizontal"
android:textSize="18sp"
android:textColor="?attr/colorAccent"
android:textColor="?android:attr/textColorPrimary"
android:text="@string/ask_scope_permission_title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Expand All @@ -102,7 +102,7 @@

<TextView
android:padding="10dp"
android:textColor="?attr/colorPrimary"
android:textColor="?android:attr/textColorSecondary"
android:textSize="12sp"
android:text="@string/ask_permission_tos"
android:layout_width="match_parent"
Expand Down Expand Up @@ -132,4 +132,4 @@
android:layout_height="wrap_content" />
</LinearLayout>

</LinearLayout>
</LinearLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@

<TextView
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:textSize="12sp"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
android:id="@android:id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>