diff options
author | Fred Quintana <fredq@google.com> | 2012-05-23 12:37:00 -0700 |
---|---|---|
committer | Fred Quintana <fredq@google.com> | 2012-05-24 14:34:43 -0700 |
commit | d9640ec712806508877868d08aafaa2d715ff441 (patch) | |
tree | 7f48982b04add7d3ebd4c82bf1cee0595a29d40a /core/java/android/accounts/GrantCredentialsPermissionActivity.java | |
parent | c1cabdfbbb5de2c286fc9a4fe995b7b630a74a0d (diff) | |
download | frameworks_base-d9640ec712806508877868d08aafaa2d715ff441.zip frameworks_base-d9640ec712806508877868d08aafaa2d715ff441.tar.gz frameworks_base-d9640ec712806508877868d08aafaa2d715ff441.tar.bz2 |
Add an updateAppPermission() API call to the AccountManagerService AIDL
and have the GrantCredentialsPermissionActivity call that instead of a
static so that it can be made to run in a different process than the
AccountManagerService. Protect this call by checking that the caller
has the same UID as the system process.
Bug: 6545417
Change-Id: I295e65cad68883349a47e7927c171af45c89b229
Diffstat (limited to 'core/java/android/accounts/GrantCredentialsPermissionActivity.java')
-rw-r--r-- | core/java/android/accounts/GrantCredentialsPermissionActivity.java | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/core/java/android/accounts/GrantCredentialsPermissionActivity.java b/core/java/android/accounts/GrantCredentialsPermissionActivity.java index 4419c8c..8b01c6a 100644 --- a/core/java/android/accounts/GrantCredentialsPermissionActivity.java +++ b/core/java/android/accounts/GrantCredentialsPermissionActivity.java @@ -16,22 +16,22 @@ package android.accounts; import android.app.Activity; +import android.content.pm.RegisteredServicesCache; +import android.content.res.Resources; import android.os.Bundle; -import android.os.RemoteException; import android.widget.TextView; import android.widget.LinearLayout; -import android.widget.ImageView; import android.view.View; import android.view.LayoutInflater; -import android.view.Window; import android.content.Context; import android.content.Intent; import android.content.pm.PackageManager; -import android.content.pm.RegisteredServicesCache; import android.text.TextUtils; -import android.graphics.drawable.Drawable; import com.android.internal.R; +import java.io.IOException; +import java.net.Authenticator; + /** * @hide */ @@ -48,7 +48,6 @@ public class GrantCredentialsPermissionActivity extends Activity implements View private int mUid; private Bundle mResultBundle = null; protected LayoutInflater mInflater; - private final AccountManagerService accountManagerService = AccountManagerService.getSingleton(); protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -81,7 +80,7 @@ public class GrantCredentialsPermissionActivity extends Activity implements View String accountTypeLabel; try { - accountTypeLabel = accountManagerService.getAccountLabel(mAccount.type); + accountTypeLabel = getAccountLabel(mAccount); } catch (IllegalArgumentException e) { // label or resource was missing. abort the activity. setResult(Activity.RESULT_CANCELED); @@ -92,28 +91,27 @@ public class GrantCredentialsPermissionActivity extends Activity implements View 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); + final AccountManagerCallback<String> callback = new AccountManagerCallback<String>() { + public void run(AccountManagerFuture<String> future) { + try { + final String authTokenLabel = future.getResult(); + if (!TextUtils.isEmpty(authTokenLabel)) { + runOnUiThread(new Runnable() { + public void run() { + if (!isFinishing()) { + authTokenTypeView.setText(authTokenLabel); + authTokenTypeView.setVisibility(View.VISIBLE); + } } - } - }); + }); + } + } catch (OperationCanceledException e) { + } catch (IOException e) { + } catch (AuthenticatorException e) { } } - - public void onError(int code, String message) { - } }; - - accountManagerService.getAuthTokenLabel(response, mAccount, mAuthTokenType, mUid); + AccountManager.get(this).getAuthTokenLabel(mAccount.type, mAuthTokenType, callback, null); findViewById(R.id.allow_button).setOnClickListener(this); findViewById(R.id.deny_button).setOnClickListener(this); @@ -134,6 +132,24 @@ public class GrantCredentialsPermissionActivity extends Activity implements View ((TextView) findViewById(R.id.account_type)).setText(accountTypeLabel); } + private String getAccountLabel(Account account) { + final AuthenticatorDescription[] authenticatorTypes = + AccountManager.get(this).getAuthenticatorTypes(); + for (int i = 0, N = authenticatorTypes.length; i < N; i++) { + final AuthenticatorDescription desc = authenticatorTypes[i]; + if (desc.type.equals(account.type)) { + try { + return createPackageContext(desc.packageName, 0).getString(desc.labelId); + } catch (PackageManager.NameNotFoundException e) { + return account.type; + } catch (Resources.NotFoundException e) { + return account.type; + } + } + } + return account.type; + } + private View newPackageView(String packageLabel) { View view = mInflater.inflate(R.layout.permissions_package_list_item, null); ((TextView) view.findViewById(R.id.package_label)).setText(packageLabel); @@ -143,7 +159,7 @@ public class GrantCredentialsPermissionActivity extends Activity implements View public void onClick(View v) { switch (v.getId()) { case R.id.allow_button: - accountManagerService.grantAppPermission(mAccount, mAuthTokenType, mUid); + AccountManager.get(this).updateAppPermission(mAccount, mAuthTokenType, mUid, true); Intent result = new Intent(); result.putExtra("retry", true); setResult(RESULT_OK, result); @@ -151,7 +167,7 @@ public class GrantCredentialsPermissionActivity extends Activity implements View break; case R.id.deny_button: - accountManagerService.revokeAppPermission(mAccount, mAuthTokenType, mUid); + AccountManager.get(this).updateAppPermission(mAccount, mAuthTokenType, mUid, false); setResult(RESULT_CANCELED); break; } |