Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c4989b1b authored by Fred Quintana's avatar Fred Quintana
Browse files

update the authtoken permission granting UI

parent 43f2b4e9
Loading
Loading
Loading
Loading
+52 −87
Original line number Diff line number Diff line
@@ -18,14 +18,16 @@ package android.accounts;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.view.View;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import android.graphics.drawable.Drawable;
import com.android.internal.R;

/**
@@ -43,62 +45,68 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
    private String mAuthTokenType;
    private int mUid;
    private Bundle mResultBundle = null;
    protected LayoutInflater mInflater;

    protected void onCreate(Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        super.onCreate(savedInstanceState);
        getWindow().setContentView(R.layout.grant_credentials_permission);
        mAccount = getIntent().getExtras().getParcelable(EXTRAS_ACCOUNT);
        mAuthTokenType = getIntent().getExtras().getString(EXTRAS_AUTH_TOKEN_TYPE);
        mUid = getIntent().getExtras().getInt(EXTRAS_REQUESTING_UID);
        final String accountTypeLabel =
                getIntent().getExtras().getString(EXTRAS_ACCOUNT_TYPE_LABEL);
        final String[] packages = getIntent().getExtras().getStringArray(EXTRAS_PACKAGES);
        setContentView(R.layout.grant_credentials_permission);

        findViewById(R.id.allow).setOnClickListener(this);
        findViewById(R.id.deny).setOnClickListener(this);
        mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        TextView messageView = (TextView) getWindow().findViewById(R.id.message);
        String authTokenLabel = getIntent().getExtras().getString(EXTRAS_AUTH_TOKEN_LABEL);
        if (authTokenLabel.length() == 0) {
            CharSequence grantCredentialsPermissionFormat = getResources().getText(
                    R.string.grant_credentials_permission_message_desc);
            messageView.setText(String.format(grantCredentialsPermissionFormat.toString(),
                    mAccount.name, accountTypeLabel));
        } else {
            CharSequence grantCredentialsPermissionFormat = getResources().getText(
                    R.string.grant_credentials_permission_message_with_authtokenlabel_desc);
            messageView.setText(String.format(grantCredentialsPermissionFormat.toString(),
                    authTokenLabel, mAccount.name, accountTypeLabel));
        }
        final Bundle extras = getIntent().getExtras();
        mAccount = extras.getParcelable(EXTRAS_ACCOUNT);
        mAuthTokenType = extras.getString(EXTRAS_AUTH_TOKEN_TYPE);
        mUid = extras.getInt(EXTRAS_REQUESTING_UID);
        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);

        findViewById(R.id.allow_button).setOnClickListener(this);
        findViewById(R.id.deny_button).setOnClickListener(this);

        LinearLayout packagesListView = (LinearLayout) findViewById(R.id.packages_list);

        String[] packageLabels = new String[packages.length];
        final PackageManager pm = getPackageManager();
        for (int i = 0; i < packages.length; i++) {
        for (String pkg : packages) {
            String packageLabel;
            try {
                packageLabels[i] =
                        pm.getApplicationLabel(pm.getApplicationInfo(packages[i], 0)).toString();
                packageLabel = pm.getApplicationLabel(pm.getApplicationInfo(pkg, 0)).toString();
            } catch (PackageManager.NameNotFoundException e) {
                packageLabels[i] = packages[i];
                packageLabel = pkg;
            }
            packagesListView.addView(newPackageView(packageLabel));
        }
        ((ListView) findViewById(R.id.packages_list)).setAdapter(
                new PackagesArrayAdapter(this, packageLabels));

        ((TextView) findViewById(R.id.account_name)).setText(mAccount.name);
        ((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) {
        View view = mInflater.inflate(R.layout.permissions_package_list_item, null);
        ((TextView) view.findViewById(R.id.package_label)).setText(packageLabel);
        return view;
    }

    public void onClick(View v) {
        final AccountManagerService accountManagerService = AccountManagerService.getSingleton();
        switch (v.getId()) {
            case R.id.allow:
                AccountManagerService.getSingleton().grantAppPermission(mAccount, mAuthTokenType,
                        mUid);
            case R.id.allow_button:
                accountManagerService.grantAppPermission(mAccount, mAuthTokenType, mUid);
                Intent result = new Intent();
                result.putExtra("retry", true);
                setResult(RESULT_OK, result);
                setAccountAuthenticatorResult(result.getExtras());
                break;

            case R.id.deny:
                AccountManagerService.getSingleton().revokeAppPermission(mAccount, mAuthTokenType,
                        mUid);
            case R.id.deny_button:
                accountManagerService.revokeAppPermission(mAccount, mAuthTokenType, mUid);
                setResult(RESULT_CANCELED);
                break;
        }
@@ -110,63 +118,20 @@ public class GrantCredentialsPermissionActivity extends Activity implements View
    }

    /**
     * Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present.
     * Sends the result or a {@link AccountManager#ERROR_CODE_CANCELED} error if a
     * result isn't present.
     */
    public void finish() {
        Intent intent = getIntent();
        AccountAuthenticatorResponse accountAuthenticatorResponse =
                intent.getParcelableExtra(EXTRAS_RESPONSE);
        if (accountAuthenticatorResponse != null) {
        AccountAuthenticatorResponse response = intent.getParcelableExtra(EXTRAS_RESPONSE);
        if (response != null) {
            // send the result bundle back if set, otherwise send an error.
            if (mResultBundle != null) {
                accountAuthenticatorResponse.onResult(mResultBundle);
                response.onResult(mResultBundle);
            } else {
                accountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
                response.onError(AccountManager.ERROR_CODE_CANCELED, "canceled");
            }
        }
        super.finish();
    }

    private static class PackagesArrayAdapter extends ArrayAdapter<String> {
        protected LayoutInflater mInflater;
        private static final int mResource = R.layout.simple_list_item_1;

        public PackagesArrayAdapter(Context context, String[] items) {
            super(context, mResource, items);
            mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        }

        static class ViewHolder {
            TextView label;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // A ViewHolder keeps references to children views to avoid unneccessary calls
            // to findViewById() on each row.
            ViewHolder holder;

            // When convertView is not null, we can reuse it directly, there is no need
            // to reinflate it. We only inflate a new View when the convertView supplied
            // by ListView is null.
            if (convertView == null) {
                convertView = mInflater.inflate(mResource, null);

                // Creates a ViewHolder and store references to the two children views
                // we want to bind data to.
                holder = new ViewHolder();
                holder.label = (TextView) convertView.findViewById(R.id.text1);

                convertView.setTag(holder);
            } else {
                // Get the ViewHolder back to get fast access to the TextView
                // and the ImageView.
                holder = (ViewHolder) convertView.getTag();
            }

            holder.label.setText(getItem(position));

            return convertView;
        }
    }
}
+149 −27
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
**     http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
/**
 * Copyright (c) 2008, Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <!-- The header -->
    <TextView
        android:id="@+id/header_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="@color/white"
        android:textStyle="bold"
        android:text="@string/grant_permissions_header_text"
        android:shadowColor="@color/shadow"
        android:shadowRadius="2"
        android:singleLine="true"
        android:background="@drawable/title_bar_medium"
        android:gravity="left|center_vertical"
	android:paddingLeft="19dip"
        android:ellipsize="marquee" />

    <!-- The list of packages that correspond to the requesting UID
    and the account/authtokenType that is being requested -->
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:layout_weight="1"
        android:gravity="top|center_horizontal"
        android:foreground="@drawable/title_bar_shadow">

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingTop="14dip"
            android:orientation="vertical">

            <TextView
                android:id="@+id/grant_credentials_permission_message_header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
        android:id="@+id/message" />
    <Button android:id="@+id/allow"
                android:text="@string/grant_credentials_permission_message_header"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:paddingLeft="19dip"
                android:paddingBottom="12dip" />

            <LinearLayout
                android:id="@+id/packages_list"
                android:orientation="vertical"
                android:paddingLeft="16dip"
                android:paddingRight="12dip"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <RelativeLayout
                android:paddingLeft="16dip"
                android:paddingRight="12dip"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                <ImageView
                    android:id="@+id/permission_icon"
                    android:layout_width="30dip"
                    android:layout_height="30dip"
                    android:src="@drawable/ic_bullet_key_permission"
                    android:layout_alignParentLeft="true"
                    android:scaleType="fitCenter" />

                <TextView
                    android:id="@+id/account_type"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@color/perms_dangerous_perm_color"
                    android:textStyle="bold"
                    android:paddingLeft="6dip"
                    android:layout_toRightOf="@id/permission_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/account_name"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/perms_dangerous_perm_color"
                    android:layout_marginTop="-4dip"
                    android:paddingBottom="8dip"
                    android:paddingLeft="6dip"
                    android:layout_below="@id/account_type"
                    android:layout_toRightOf="@id/permission_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />

                <TextView
                    android:id="@+id/authtoken_type"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@color/perms_dangerous_perm_color"
                    android:textStyle="bold"
                    android:layout_marginTop="-4dip"
                    android:paddingBottom="8dip"
                    android:paddingLeft="6dip"
                    android:layout_below="@id/account_name"
                    android:layout_toRightOf="@id/permission_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content" />
            </RelativeLayout>

            <TextView
                android:id="@+id/grant_credentials_permission_message_footer"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
        android:text="@string/allow" />
                android:text="@string/grant_credentials_permission_message_footer"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:paddingLeft="19dip"
                android:paddingBottom="12dip" />
        </LinearLayout>
    </ScrollView>

    <Button android:id="@+id/deny"
    <!-- The buttons to allow or deny -->
    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="52dip"
        android:background="@drawable/bottom_bar"
        android:paddingTop="4dip"
        android:paddingLeft="2dip"
        android:paddingRight="2dip">

        <Button
            android:id="@+id/allow_button"
            android:text="@string/allow"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
        android:text="@string/deny" />
            android:layout_weight="2" />

    <ListView android:id="@+id/packages_list"
       android:layout_width="fill_parent" android:layout_height="fill_parent"/>
        <Button
            android:id="@+id/deny_button"
            android:text="@string/deny"
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:layout_weight="2" />

    </LinearLayout>
</LinearLayout>
+67 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!--
  Defines the layout of an account and authtoken type permission item.
  Contains an icon, the account type and name and the authtoken type.
-->

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/permission_icon"
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:drawable="@drawable/ic_bullet_key_permission"
        android:layout_alignParentLeft="true"
        android:scaleType="fitCenter" />


    <TextView
        android:id="@+id/account_type"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:paddingLeft="6dip"
        android:layout_toRightOf="@id/permission_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/account_name"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_marginTop="-4dip"
        android:paddingBottom="8dip"
        android:paddingLeft="6dip"
        android:layout_below="@id/account_type"
        android:layout_toRightOf="@id/permission_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/authtoken_type"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:layout_marginTop="-4dip"
        android:paddingBottom="8dip"
        android:paddingLeft="6dip"
        android:layout_below="@id/account_name"
        android:layout_toRightOf="@id/permission_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
+45 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2009 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<!--
  Defines the layout of a single package item.
  Contains a bullet point icon and the name of the package.
-->

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/package_icon"
        android:layout_width="30dip"
        android:layout_height="30dip"
        android:layout_alignParentLeft="true"
        android:src="@drawable/ic_text_dot"
        android:scaleType="fitCenter" />


    <TextView
        android:id="@+id/package_label"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textStyle="bold"
        android:paddingLeft="6dip"
        android:layout_toRightOf="@id/package_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>
+0 −2
Original line number Diff line number Diff line
@@ -837,8 +837,6 @@
    <string name="create_contact_using" msgid="4947405226788104538">"Vytvořit kontakt"\n"pro <xliff:g id="NUMBER">%s</xliff:g>."</string>
    <string name="accessibility_compound_button_selected" msgid="5612776946036285686">"Zaškrtnuto"</string>
    <string name="accessibility_compound_button_unselected" msgid="8864512895673924091">"Nezaškrtnuto"</string>
    <string name="grant_credentials_permission_message_desc" msgid="6883276587034335667">"Uvedené aplikace od <xliff:g id="APPLICATION">%2$s</xliff:g> požadují oprávnění přistupovat k přihlašovacím údajům účtu <xliff:g id="ACCOUNT">%1$s</xliff:g>. Chcete toto oprávnění udělit? Pokud je udělíte, vaše odpověď se uloží a tato výzva se již nebude zobrazovat."</string>
    <string name="grant_credentials_permission_message_with_authtokenlabel_desc" msgid="3159007601893584687">"Uvedené aplikace požadují od <xliff:g id="APPLICATION">%3$s</xliff:g> oprávnění přistupovat k přihlašovacím údajům (typ: <xliff:g id="TYPE">%1$s</xliff:g>) účtu <xliff:g id="ACCOUNT">%2$s</xliff:g>. Chcete toto oprávnění udělit? Pokud je udělíte, vaše odpověď se uloží a tato výzva se již nebude zobrazovat."</string>
    <string name="allow" msgid="7225948811296386551">"Povolit"</string>
    <string name="deny" msgid="2081879885755434506">"Odepřít"</string>
    <string name="permission_request_notification_title" msgid="5390555465778213840">"Požadováno oprávnění"</string>
Loading