mirror of https://github.com/YTVanced/VancedMicroG
Parse OAuth2 consent data
This commit is contained in:
parent
a1a27167e6
commit
15d772c195
|
@ -24,6 +24,7 @@ import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.Html;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -47,6 +48,8 @@ import static android.accounts.AccountManager.KEY_ACCOUNT_TYPE;
|
||||||
import static android.accounts.AccountManager.KEY_ANDROID_PACKAGE_NAME;
|
import static android.accounts.AccountManager.KEY_ANDROID_PACKAGE_NAME;
|
||||||
import static android.accounts.AccountManager.KEY_AUTHTOKEN;
|
import static android.accounts.AccountManager.KEY_AUTHTOKEN;
|
||||||
import static android.accounts.AccountManager.KEY_CALLER_UID;
|
import static android.accounts.AccountManager.KEY_CALLER_UID;
|
||||||
|
import static android.view.View.GONE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
||||||
public static final String EXTRA_FROM_ACCOUNT_MANAGER = "from_account_manager";
|
public static final String EXTRA_FROM_ACCOUNT_MANAGER = "from_account_manager";
|
||||||
|
@ -79,9 +82,11 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
||||||
if (getIntent().hasExtra(EXTRA_CONSENT_DATA)) {
|
if (getIntent().hasExtra(EXTRA_CONSENT_DATA)) {
|
||||||
try {
|
try {
|
||||||
consentData = new Wire().parseFrom(getIntent().getByteArrayExtra(EXTRA_CONSENT_DATA), ConsentData.class);
|
consentData = new Wire().parseFrom(getIntent().getByteArrayExtra(EXTRA_CONSENT_DATA), ConsentData.class);
|
||||||
Log.d(TAG, "Consent: " + consentData);
|
} catch (Exception e) {
|
||||||
} catch (Exception ignored) {
|
Log.w(TAG, e);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "No Consent details attached");
|
||||||
}
|
}
|
||||||
if (getIntent().hasExtra(EXTRA_FROM_ACCOUNT_MANAGER)) fromAccountManager = true;
|
if (getIntent().hasExtra(EXTRA_FROM_ACCOUNT_MANAGER)) fromAccountManager = true;
|
||||||
int callerUid = getIntent().getIntExtra(KEY_CALLER_UID, 0);
|
int callerUid = getIntent().getIntExtra(KEY_CALLER_UID, 0);
|
||||||
|
@ -146,8 +151,8 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
||||||
authManager.setPermitted(true);
|
authManager.setPermitted(true);
|
||||||
findViewById(android.R.id.button1).setEnabled(false);
|
findViewById(android.R.id.button1).setEnabled(false);
|
||||||
findViewById(android.R.id.button2).setEnabled(false);
|
findViewById(android.R.id.button2).setEnabled(false);
|
||||||
findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
findViewById(R.id.progress_bar).setVisibility(VISIBLE);
|
||||||
findViewById(R.id.no_progress_bar).setVisibility(View.GONE);
|
findViewById(R.id.no_progress_bar).setVisibility(GONE);
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -205,6 +210,17 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
||||||
return "unknown";
|
return "unknown";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getScopeDescription(String scope) {
|
||||||
|
if (consentData != null) {
|
||||||
|
for (ConsentData.ScopeDetails scopeDetails : consentData.scopes) {
|
||||||
|
if (scope.equals(scopeDetails.id)) {
|
||||||
|
return scopeDetails.description;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private String getServiceLabel(String service) {
|
private String getServiceLabel(String service) {
|
||||||
int labelResource = getResources().getIdentifier("permission_service_" + service + "_label", "string", getPackageName());
|
int labelResource = getResources().getIdentifier("permission_service_" + service + "_label", "string", getPackageName());
|
||||||
if (labelResource != 0) {
|
if (labelResource != 0) {
|
||||||
|
@ -241,16 +257,26 @@ public class AskPermissionActivity extends AccountAuthenticatorActivity {
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
String item = getItem(position);
|
String item = getItem(position);
|
||||||
String label;
|
String label;
|
||||||
|
String description;
|
||||||
if (isOAuth()) {
|
if (isOAuth()) {
|
||||||
label = getScopeLabel(item);
|
label = getScopeLabel(item);
|
||||||
|
description = getScopeDescription(item);
|
||||||
} else {
|
} else {
|
||||||
label = getServiceLabel(item);
|
label = getServiceLabel(item);
|
||||||
|
description = null;
|
||||||
}
|
}
|
||||||
View view = convertView;
|
View view = convertView;
|
||||||
if (view == null) {
|
if (view == null) {
|
||||||
view = LayoutInflater.from(AskPermissionActivity.this).inflate(R.layout.ask_permission_list_entry, null);
|
view = LayoutInflater.from(AskPermissionActivity.this).inflate(R.layout.ask_permission_list_entry, null);
|
||||||
}
|
}
|
||||||
((TextView) view.findViewById(android.R.id.text1)).setText(label);
|
((TextView) view.findViewById(android.R.id.text1)).setText(label);
|
||||||
|
TextView textView = (TextView) view.findViewById(android.R.id.text2);
|
||||||
|
if (description != null && !description.isEmpty()) {
|
||||||
|
textView.setText(Html.fromHtml(description.trim().replace("\n","<br>")));
|
||||||
|
textView.setVisibility(VISIBLE);
|
||||||
|
} else {
|
||||||
|
textView.setVisibility(GONE);
|
||||||
|
}
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,8 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bundle getToken(String accountName, String scope, Bundle extras) throws RemoteException {
|
public Bundle getToken(String accountName, String scope, Bundle extras) throws RemoteException {
|
||||||
String packageName = extras.getString(KEY_ANDROID_PACKAGE_NAME, extras.getString(KEY_CLIENT_PACKAGE_NAME, null));
|
String packageName = extras.getString(KEY_ANDROID_PACKAGE_NAME);
|
||||||
|
if (packageName == null || packageName.isEmpty()) packageName = extras.getString(KEY_CLIENT_PACKAGE_NAME);
|
||||||
int callerUid = extras.getInt(KEY_CALLER_UID, 0);
|
int callerUid = extras.getInt(KEY_CALLER_UID, 0);
|
||||||
PackageUtils.checkPackageUid(context, packageName, callerUid, getCallingUid());
|
PackageUtils.checkPackageUid(context, packageName, callerUid, getCallingUid());
|
||||||
boolean notify = extras.getBoolean(KEY_HANDLE_NOTIFICATION, false);
|
boolean notify = extras.getBoolean(KEY_HANDLE_NOTIFICATION, false);
|
||||||
|
@ -85,7 +86,7 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
||||||
i.putExtra(KEY_ACCOUNT_NAME, accountName);
|
i.putExtra(KEY_ACCOUNT_NAME, accountName);
|
||||||
i.putExtra(KEY_AUTHTOKEN, scope);
|
i.putExtra(KEY_AUTHTOKEN, scope);
|
||||||
if (res.consentDataBase64 != null)
|
if (res.consentDataBase64 != null)
|
||||||
i.putExtra(EXTRA_CONSENT_DATA, Base64.decode(res.consentDataBase64, Base64.DEFAULT));
|
i.putExtra(EXTRA_CONSENT_DATA, Base64.decode(res.consentDataBase64, Base64.URL_SAFE));
|
||||||
if (notify) {
|
if (notify) {
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(i);
|
context.startActivity(i);
|
||||||
|
@ -96,7 +97,7 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
throw new RemoteException(e.getMessage());
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +108,11 @@ public class AuthManagerServiceImpl extends IAuthManagerService.Stub {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bundle clearToken(String token, Bundle extras) throws RemoteException {
|
public Bundle clearToken(String token, Bundle extras) throws RemoteException {
|
||||||
|
String packageName = extras.getString(KEY_ANDROID_PACKAGE_NAME, extras.getString(KEY_CLIENT_PACKAGE_NAME));
|
||||||
|
int callerUid = extras.getInt(KEY_CALLER_UID, 0);
|
||||||
|
PackageUtils.checkPackageUid(context, packageName, callerUid, getCallingUid());
|
||||||
|
|
||||||
|
Log.d(TAG, "clearToken: token:" + token + " extras:" + extras);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,23 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
android:padding="6dp"
|
android:padding="6dp"
|
||||||
android:textSize="16sp"
|
android:orientation="vertical"
|
||||||
android:id="@android:id/text1"
|
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:textSize="12sp"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:id="@android:id/text2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
Loading…
Reference in New Issue