summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnthony Hugh <ahugh@google.com>2015-08-19 11:44:43 -0700
committerAnthony Hugh <ahugh@google.com>2015-08-21 16:21:28 -0700
commit9478120abc48a8934e5de14f7cf49342cef5485c (patch)
treee995ef96a7dc37c4c079c46e9b87a94a0d454d77 /src
parent24938647726a06f636dc8c9f1195a378ebb07995 (diff)
downloadandroid_packages_apps_PackageInstaller-9478120abc48a8934e5de14f7cf49342cef5485c.tar.gz
android_packages_apps_PackageInstaller-9478120abc48a8934e5de14f7cf49342cef5485c.tar.bz2
android_packages_apps_PackageInstaller-9478120abc48a8934e5de14f7cf49342cef5485c.zip
Implement base version of GrantPermissions dialog
With the Emerald release, we need to support the new permission APIs. This changelist adds a dialog for the Activity.requestPermissions() API so that users can request permissions. This check in is a functional version, but not polished. will need to be a follow up CL to add the correct animations and update the UI to the appropriate redlines. The implementation for the confirmation dialog is modeled after the one in the clockwork libs/Views folder. There are some tweaks to match the designed behavior of the permission dialog. When there's more time in the future, we should try to condense this to one implementation. This is a resubmit without the wearable-support lib. I will figure out how to get that referenced in the next UI pass. BUG: 23118402 Change-Id: Ib2fb94b356aa965b999b3e12726fda86928a963e
Diffstat (limited to 'src')
-rw-r--r--src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java7
-rw-r--r--src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java159
-rw-r--r--src/com/android/packageinstaller/permission/ui/PermissionConfirmationViewHandler.java149
3 files changed, 315 insertions, 0 deletions
diff --git a/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java b/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
index 0c087350..c1597f16 100644
--- a/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
+++ b/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
@@ -73,6 +73,8 @@ public class GrantPermissionsActivity extends OverlayTouchActivity
if (Utils.isTelevision(this)) {
mViewHandler = new GrantPermissionsTvViewHandler(this).setResultListener(this);
+ } else if (isWatch()) {
+ mViewHandler = new GrantPermissionsWatchViewHandler(this).setResultListener(this);
} else {
mViewHandler = new GrantPermissionsDefaultViewHandler(this).setResultListener(this);
}
@@ -368,6 +370,11 @@ public class GrantPermissionsActivity extends OverlayTouchActivity
SafetyNetLogger.logPermissionsRequested(mAppPermissions.getPackageInfo(), groups);
}
+ private boolean isWatch() {
+ PackageManager pm = getPackageManager();
+ return pm.hasSystemFeature(pm.FEATURE_WATCH);
+ }
+
private static final class GroupState {
static final int STATE_UNKNOWN = 0;
static final int STATE_ALLOWED = 1;
diff --git a/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java b/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java
new file mode 100644
index 00000000..ac573c43
--- /dev/null
+++ b/src/com/android/packageinstaller/permission/ui/GrantPermissionsWatchViewHandler.java
@@ -0,0 +1,159 @@
+package com.android.packageinstaller.permission.ui;
+
+import android.content.Context;
+import android.graphics.PixelFormat;
+import android.graphics.drawable.Icon;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+
+import com.android.packageinstaller.R;
+
+/**
+ * Watch-specific view handler for the grant permissions activity.
+ */
+final class GrantPermissionsWatchViewHandler extends PermissionConfirmationViewHandler
+ implements GrantPermissionsViewHandler {
+ private static final String TAG = "GrantPermissionsViewH";
+
+ private static final String ARG_GROUP_NAME = "ARG_GROUP_NAME";
+
+ private final Context mContext;
+
+ private ResultListener mResultListener;
+
+ private String mGroupName;
+ private boolean mShowDoNotAsk;
+
+ private CharSequence mMessage;
+ private String mCurrentPageText;
+ private Icon mIcon;
+
+ GrantPermissionsWatchViewHandler(Context context) {
+ super(context);
+ mContext = context;
+ }
+
+ @Override
+ public GrantPermissionsWatchViewHandler setResultListener(ResultListener listener) {
+ mResultListener = listener;
+ return this;
+ }
+
+ @Override
+ public View createView() {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "createView()");
+ }
+
+ mShowDoNotAsk = false;
+
+ return super.createView();
+ }
+
+ @Override
+ public void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams) {
+ outLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
+ outLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
+ outLayoutParams.format = PixelFormat.OPAQUE;
+ outLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
+ outLayoutParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
+ }
+
+ @Override
+ public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon,
+ CharSequence message, boolean showDoNotAsk) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, "updateUi() - groupName: " + groupName
+ + ", groupCount: " + groupCount
+ + ", groupIndex: " + groupIndex
+ + ", icon: " + icon
+ + ", message: " + message
+ + ", showDoNotAsk: " + showDoNotAsk);
+ }
+
+ mGroupName = groupName;
+ mShowDoNotAsk = showDoNotAsk;
+ mMessage = message;
+ mIcon = icon;
+ mCurrentPageText = (groupCount > 1 ?
+ mContext.getString(R.string.current_permission_template, groupIndex + 1, groupCount)
+ : null);
+
+ invalidate();
+ }
+
+ @Override
+ public void saveInstanceState(Bundle outState) {
+ outState.putString(ARG_GROUP_NAME, mGroupName);
+ }
+
+ @Override
+ public void loadInstanceState(Bundle savedInstanceState) {
+ mGroupName = savedInstanceState.getString(ARG_GROUP_NAME);
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (mResultListener != null) {
+ mResultListener.onPermissionGrantResult(mGroupName, false, false);
+ }
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public void onAllow() {
+ onClick(true /* granted */, false /* doNotAskAgain */);
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public void onDeny() {
+ onClick(false /* granted */, false /* doNotAskAgain */);
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public void onDenyDoNotAskAgain() {
+ onClick(false /* granted */, true /* doNotAskAgain */);
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public CharSequence getCurrentPageText() {
+ return mCurrentPageText;
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public Icon getPermissionIcon() {
+ return mIcon;
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public CharSequence getMessage() {
+ return mMessage;
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public int getButtonBarMode() {
+ return mShowDoNotAsk ? MODE_VERTICAL_BUTTONS : MODE_HORIZONTAL_BUTTONS;
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public CharSequence getVerticalAllowText() {
+ return mContext.getString(R.string.grant_dialog_button_allow);
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public CharSequence getVerticalDenyText() {
+ return mContext.getString(R.string.grant_dialog_button_deny);
+ }
+
+ @Override // PermissionConfirmationViewHandler
+ public CharSequence getVerticalDenyDoNotAskAgainText() {
+ return mContext.getString(R.string.grant_dialog_button_deny_dont_ask_again);
+ }
+
+ private void onClick(boolean granted, boolean doNotAskAgain) {
+ if (mResultListener != null) {
+ mResultListener.onPermissionGrantResult(mGroupName, granted, doNotAskAgain);
+ }
+ }
+}
diff --git a/src/com/android/packageinstaller/permission/ui/PermissionConfirmationViewHandler.java b/src/com/android/packageinstaller/permission/ui/PermissionConfirmationViewHandler.java
new file mode 100644
index 00000000..63ed0a45
--- /dev/null
+++ b/src/com/android/packageinstaller/permission/ui/PermissionConfirmationViewHandler.java
@@ -0,0 +1,149 @@
+package com.android.packageinstaller.permission.ui;
+
+import android.content.Context;
+import android.graphics.drawable.Icon;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ImageView;
+import android.widget.ScrollView;
+import android.widget.TextView;
+
+import com.android.packageinstaller.R;
+
+public abstract class PermissionConfirmationViewHandler implements
+ View.OnClickListener {
+ public static final int MODE_HORIZONTAL_BUTTONS = 0;
+ public static final int MODE_VERTICAL_BUTTONS = 1;
+
+ private View mRoot;
+ private TextView mCurrentPageText;
+ private ImageView mIcon;
+ private TextView mMessage;
+ private ScrollView mScrollingContainer;
+ private ViewGroup mContent;
+ private ViewGroup mHorizontalButtonBar;
+ private ViewGroup mVerticalButtonBar;
+ private Button mVerticalAllow;
+ private Button mVerticalDeny;
+ private Button mVerticalDenyDoNotAskAgain;
+ private View mButtonBarContainer;
+
+ private Context mContext;
+
+ // TODO: Move these into a builder
+ public abstract void onAllow();
+ public abstract void onDeny();
+ public abstract void onDenyDoNotAskAgain();
+ public abstract CharSequence getVerticalAllowText();
+ public abstract CharSequence getVerticalDenyText();
+ public abstract CharSequence getVerticalDenyDoNotAskAgainText();
+ public abstract CharSequence getCurrentPageText();
+ public abstract Icon getPermissionIcon();
+ public abstract CharSequence getMessage();
+
+ public PermissionConfirmationViewHandler(Context context) {
+ mContext = context;
+ }
+
+ public View createView() {
+ mRoot = LayoutInflater.from(mContext).inflate(R.layout.grant_permissions, null);
+
+ mMessage = (TextView) mRoot.findViewById(R.id.message);
+ mCurrentPageText = (TextView) mRoot.findViewById(R.id.current_page_text);
+ mIcon = (ImageView) mRoot.findViewById(R.id.icon);
+ mButtonBarContainer = mRoot.findViewById(R.id.button_bar_container);
+ mContent = (ViewGroup) mRoot.findViewById(R.id.content);
+ mScrollingContainer = (ScrollView) mRoot.findViewById(R.id.scrolling_container);
+ mHorizontalButtonBar = (ViewGroup) mRoot.findViewById(R.id.horizontal_button_bar);
+ mVerticalButtonBar = (ViewGroup) mRoot.findViewById(R.id.vertical_button_bar);
+
+ Button horizontalAllow = (Button) mRoot.findViewById(R.id.horizontal_allow_button);
+ Button horizontalDeny = (Button) mRoot.findViewById(R.id.horizontal_deny_button);
+ horizontalAllow.setOnClickListener(this);
+ horizontalDeny.setOnClickListener(this);
+
+ mVerticalAllow = (Button) mRoot.findViewById(R.id.vertical_allow_button);
+ mVerticalDeny = (Button) mRoot.findViewById(R.id.vertical_deny_button);
+ mVerticalDenyDoNotAskAgain =
+ (Button) mRoot.findViewById(R.id.vertical_deny_do_not_ask_again_button);
+ mVerticalAllow.setOnClickListener(this);
+ mVerticalDeny.setOnClickListener(this);
+ mVerticalDenyDoNotAskAgain.setOnClickListener(this);
+
+ return mRoot;
+ }
+
+ /**
+ * Child class should override this for other modes. Call invalidate() to update the UI to the
+ * new button mode.
+ * @return The current mode the layout should use for the buttons
+ */
+ public int getButtonBarMode() {
+ return MODE_HORIZONTAL_BUTTONS;
+ }
+
+ public void invalidate() {
+ CharSequence currentPageText = getCurrentPageText();
+ if (!TextUtils.isEmpty(currentPageText)) {
+ mCurrentPageText.setText(currentPageText);
+ mCurrentPageText.setVisibility(View.VISIBLE);
+ } else {
+ mCurrentPageText.setVisibility(View.INVISIBLE);
+ }
+
+ Icon icon = getPermissionIcon();
+ if (icon != null) {
+ mIcon.setImageIcon(icon);
+ mIcon.setVisibility(View.VISIBLE);
+ } else {
+ mIcon.setVisibility(View.INVISIBLE);
+ }
+
+ mMessage.setText(getMessage());
+
+ switch (getButtonBarMode()) {
+ case MODE_HORIZONTAL_BUTTONS:
+ mHorizontalButtonBar.setVisibility(View.VISIBLE);
+ mVerticalButtonBar.setVisibility(View.GONE);
+ break;
+ case MODE_VERTICAL_BUTTONS:
+ mHorizontalButtonBar.setVisibility(View.GONE);
+ mVerticalButtonBar.setVisibility(View.VISIBLE);
+ mVerticalAllow.setText(getVerticalAllowText());
+ mVerticalDeny.setText(getVerticalDenyText());
+ mVerticalDenyDoNotAskAgain.setText(getVerticalDenyDoNotAskAgainText());
+
+ mVerticalAllow.setCompoundDrawablesWithIntrinsicBounds(
+ mContext.getDrawable(R.drawable.confirm_button), null, null, null);
+ mVerticalDeny.setCompoundDrawablesWithIntrinsicBounds(
+ mContext.getDrawable(R.drawable.cancel_button), null, null, null);
+ mVerticalDenyDoNotAskAgain.setCompoundDrawablesWithIntrinsicBounds(
+ mContext.getDrawable(R.drawable.cancel_button), null, null, null);
+ break;
+ }
+
+ mScrollingContainer.scrollTo(0, 0);
+ }
+
+ @Override
+ public void onClick(View v) {
+ int id = v.getId();
+ switch (id) {
+ case R.id.horizontal_allow_button:
+ case R.id.vertical_allow_button:
+ onAllow();
+ break;
+ case R.id.horizontal_deny_button:
+ case R.id.vertical_deny_button:
+ onDeny();
+ break;
+ case R.id.vertical_deny_do_not_ask_again_button:
+ onDenyDoNotAskAgain();
+ break;
+ }
+ }
+}