am a848d344: Merge "Fix bug in permission grant system." into gingerbread
* commit 'a848d3445090e114cbfe61f1c7449122a665fba6': Fix bug in permission grant system.
This commit is contained in:
@@ -802,6 +802,44 @@ public class AccountManagerService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getAuthTokenLabel(final IAccountManagerResponse response,
|
||||||
|
final Account account, final String authTokenType) {
|
||||||
|
if (account == null) throw new IllegalArgumentException("account is null");
|
||||||
|
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
||||||
|
|
||||||
|
checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
|
||||||
|
|
||||||
|
long identityToken = clearCallingIdentity();
|
||||||
|
try {
|
||||||
|
new Session(response, account.type, false,
|
||||||
|
false /* stripAuthTokenFromResult */) {
|
||||||
|
protected String toDebugString(long now) {
|
||||||
|
return super.toDebugString(now) + ", getAuthTokenLabel"
|
||||||
|
+ ", " + account
|
||||||
|
+ ", authTokenType " + authTokenType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() throws RemoteException {
|
||||||
|
mAuthenticator.getAuthTokenLabel(this, authTokenType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onResult(Bundle result) {
|
||||||
|
if (result != null) {
|
||||||
|
String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, label);
|
||||||
|
super.onResult(bundle);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
super.onResult(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.bind();
|
||||||
|
} finally {
|
||||||
|
restoreCallingIdentity(identityToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void getAuthToken(IAccountManagerResponse response, final Account account,
|
public void getAuthToken(IAccountManagerResponse response, final Account account,
|
||||||
final String authTokenType, final boolean notifyOnAuthFailure,
|
final String authTokenType, final boolean notifyOnAuthFailure,
|
||||||
final boolean expectActivityLaunch, final Bundle loginOptions) {
|
final boolean expectActivityLaunch, final Bundle loginOptions) {
|
||||||
@@ -912,36 +950,36 @@ public class AccountManagerService
|
|||||||
.notify(getCredentialPermissionNotificationId(account, authTokenType, uid), n);
|
.notify(getCredentialPermissionNotificationId(account, authTokenType, uid), n);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Intent newGrantCredentialsPermissionIntent(Account account, int uid,
|
String getAccountLabel(String accountType) {
|
||||||
AccountAuthenticatorResponse response, String authTokenType, String authTokenLabel) {
|
|
||||||
RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> serviceInfo =
|
RegisteredServicesCache.ServiceInfo<AuthenticatorDescription> serviceInfo =
|
||||||
mAuthenticatorCache.getServiceInfo(
|
mAuthenticatorCache.getServiceInfo(
|
||||||
AuthenticatorDescription.newKey(account.type));
|
AuthenticatorDescription.newKey(accountType));
|
||||||
if (serviceInfo == null) {
|
if (serviceInfo == null) {
|
||||||
throw new IllegalArgumentException("unknown account type: " + account.type);
|
throw new IllegalArgumentException("unknown account type: " + accountType);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Context authContext;
|
final Context authContext;
|
||||||
try {
|
try {
|
||||||
authContext = mContext.createPackageContext(
|
authContext = mContext.createPackageContext(
|
||||||
serviceInfo.type.packageName, 0);
|
serviceInfo.type.packageName, 0);
|
||||||
} catch (PackageManager.NameNotFoundException e) {
|
} catch (PackageManager.NameNotFoundException e) {
|
||||||
throw new IllegalArgumentException("unknown account type: " + account.type);
|
throw new IllegalArgumentException("unknown account type: " + accountType);
|
||||||
}
|
}
|
||||||
|
return authContext.getString(serviceInfo.type.labelId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Intent newGrantCredentialsPermissionIntent(Account account, int uid,
|
||||||
|
AccountAuthenticatorResponse response, String authTokenType, String authTokenLabel) {
|
||||||
|
|
||||||
Intent intent = new Intent(mContext, GrantCredentialsPermissionActivity.class);
|
Intent intent = new Intent(mContext, GrantCredentialsPermissionActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
intent.addCategory(
|
intent.addCategory(
|
||||||
String.valueOf(getCredentialPermissionNotificationId(account, authTokenType, uid)));
|
String.valueOf(getCredentialPermissionNotificationId(account, authTokenType, uid)));
|
||||||
|
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_ACCOUNT, account);
|
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_ACCOUNT, account);
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_AUTH_TOKEN_LABEL, authTokenLabel);
|
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_AUTH_TOKEN_TYPE, authTokenType);
|
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_AUTH_TOKEN_TYPE, authTokenType);
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_RESPONSE, response);
|
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_RESPONSE, response);
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_ACCOUNT_TYPE_LABEL,
|
|
||||||
authContext.getString(serviceInfo.type.labelId));
|
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_PACKAGES,
|
|
||||||
mContext.getPackageManager().getPackagesForUid(uid));
|
|
||||||
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_REQUESTING_UID, uid);
|
intent.putExtra(GrantCredentialsPermissionActivity.EXTRAS_REQUESTING_UID, uid);
|
||||||
|
|
||||||
return intent;
|
return intent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ package android.accounts;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -26,6 +27,7 @@ import android.view.Window;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.RegisteredServicesCache;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import com.android.internal.R;
|
import com.android.internal.R;
|
||||||
@@ -46,6 +48,7 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
|
|||||||
private int mUid;
|
private int mUid;
|
||||||
private Bundle mResultBundle = null;
|
private Bundle mResultBundle = null;
|
||||||
protected LayoutInflater mInflater;
|
protected LayoutInflater mInflater;
|
||||||
|
private final AccountManagerService accountManagerService = AccountManagerService.getSingleton();
|
||||||
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
@@ -55,27 +58,56 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
|
|||||||
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
|
|
||||||
final Bundle extras = getIntent().getExtras();
|
final Bundle extras = getIntent().getExtras();
|
||||||
|
|
||||||
|
// Grant 'account'/'type' to mUID
|
||||||
mAccount = extras.getParcelable(EXTRAS_ACCOUNT);
|
mAccount = extras.getParcelable(EXTRAS_ACCOUNT);
|
||||||
mAuthTokenType = extras.getString(EXTRAS_AUTH_TOKEN_TYPE);
|
mAuthTokenType = extras.getString(EXTRAS_AUTH_TOKEN_TYPE);
|
||||||
|
mUid = extras.getInt(EXTRAS_REQUESTING_UID);
|
||||||
|
final PackageManager pm = getPackageManager();
|
||||||
|
final String[] packages = pm.getPackagesForUid(mUid);
|
||||||
|
|
||||||
if (mAccount == null || mAuthTokenType == null) {
|
if (mAccount == null || mAuthTokenType == null || packages == null) {
|
||||||
// we were somehow started with bad parameters. abort the activity.
|
// we were somehow started with bad parameters. abort the activity.
|
||||||
setResult(Activity.RESULT_CANCELED);
|
setResult(Activity.RESULT_CANCELED);
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mUid = extras.getInt(EXTRAS_REQUESTING_UID);
|
final String accountTypeLabel = accountManagerService.getAccountLabel(mAccount.type);
|
||||||
final String accountTypeLabel = extras.getString(EXTRAS_ACCOUNT_TYPE_LABEL);
|
|
||||||
final String[] packages = extras.getStringArray(EXTRAS_PACKAGES);
|
|
||||||
final String authTokenLabel = extras.getString(EXTRAS_AUTH_TOKEN_LABEL);
|
final TextView authTokenTypeView = (TextView) findViewById(R.id.authtoken_type);
|
||||||
|
authTokenTypeView.setVisibility(View.GONE);
|
||||||
|
|
||||||
|
/** Handles the responses from the AccountManager */
|
||||||
|
IAccountManagerResponse response = new IAccountManagerResponse.Stub() {
|
||||||
|
public void onResult(Bundle bundle) {
|
||||||
|
final String authTokenLabel =
|
||||||
|
bundle.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
|
||||||
|
if (!TextUtils.isEmpty(authTokenLabel)) {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
if (!isFinishing()) {
|
||||||
|
authTokenTypeView.setText(authTokenLabel);
|
||||||
|
authTokenTypeView.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onError(int code, String message) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
accountManagerService.getAuthTokenLabel(
|
||||||
|
response, mAccount, mAuthTokenType);
|
||||||
|
|
||||||
findViewById(R.id.allow_button).setOnClickListener(this);
|
findViewById(R.id.allow_button).setOnClickListener(this);
|
||||||
findViewById(R.id.deny_button).setOnClickListener(this);
|
findViewById(R.id.deny_button).setOnClickListener(this);
|
||||||
|
|
||||||
LinearLayout packagesListView = (LinearLayout) findViewById(R.id.packages_list);
|
LinearLayout packagesListView = (LinearLayout) findViewById(R.id.packages_list);
|
||||||
|
|
||||||
final PackageManager pm = getPackageManager();
|
|
||||||
for (String pkg : packages) {
|
for (String pkg : packages) {
|
||||||
String packageLabel;
|
String packageLabel;
|
||||||
try {
|
try {
|
||||||
@@ -88,12 +120,6 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
|
|||||||
|
|
||||||
((TextView) findViewById(R.id.account_name)).setText(mAccount.name);
|
((TextView) findViewById(R.id.account_name)).setText(mAccount.name);
|
||||||
((TextView) findViewById(R.id.account_type)).setText(accountTypeLabel);
|
((TextView) findViewById(R.id.account_type)).setText(accountTypeLabel);
|
||||||
TextView authTokenTypeView = (TextView) findViewById(R.id.authtoken_type);
|
|
||||||
if (TextUtils.isEmpty(authTokenLabel)) {
|
|
||||||
authTokenTypeView.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
authTokenTypeView.setText(authTokenLabel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private View newPackageView(String packageLabel) {
|
private View newPackageView(String packageLabel) {
|
||||||
@@ -103,7 +129,6 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
final AccountManagerService accountManagerService = AccountManagerService.getSingleton();
|
|
||||||
switch (v.getId()) {
|
switch (v.getId()) {
|
||||||
case R.id.allow_button:
|
case R.id.allow_button:
|
||||||
accountManagerService.grantAppPermission(mAccount, mAuthTokenType, mUid);
|
accountManagerService.grantAppPermission(mAccount, mAuthTokenType, mUid);
|
||||||
|
|||||||
Reference in New Issue
Block a user