1 package com.android.packageinstaller.permission.ui; 2 3 import android.content.Context; 4 import android.graphics.PixelFormat; 5 import android.graphics.drawable.Drawable; 6 import android.graphics.drawable.Icon; 7 import android.os.Bundle; 8 import android.util.Log; 9 import android.view.View; 10 import android.view.WindowManager; 11 12 import com.android.packageinstaller.R; 13 import com.android.packageinstaller.permission.ui.wear.ConfirmationViewHandler; 14 15 /** 16 * Watch-specific view handler for the grant permissions activity. 17 */ 18 final class GrantPermissionsWatchViewHandler extends ConfirmationViewHandler 19 implements GrantPermissionsViewHandler { 20 private static final String TAG = "GrantPermsWatchViewH"; 21 22 private static final String ARG_GROUP_NAME = "ARG_GROUP_NAME"; 23 24 private final Context mContext; 25 26 private ResultListener mResultListener; 27 28 private String mGroupName; 29 private boolean mShowDoNotAsk; 30 31 private CharSequence mMessage; 32 private String mCurrentPageText; 33 private Icon mIcon; 34 GrantPermissionsWatchViewHandler(Context context)35 GrantPermissionsWatchViewHandler(Context context) { 36 super(context); 37 mContext = context; 38 } 39 40 @Override setResultListener(ResultListener listener)41 public GrantPermissionsWatchViewHandler setResultListener(ResultListener listener) { 42 mResultListener = listener; 43 return this; 44 } 45 46 @Override createView()47 public View createView() { 48 if (Log.isLoggable(TAG, Log.DEBUG)) { 49 Log.d(TAG, "createView()"); 50 } 51 52 mShowDoNotAsk = false; 53 54 return super.createView(); 55 } 56 57 @Override updateWindowAttributes(WindowManager.LayoutParams outLayoutParams)58 public void updateWindowAttributes(WindowManager.LayoutParams outLayoutParams) { 59 outLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; 60 outLayoutParams.height = WindowManager.LayoutParams.MATCH_PARENT; 61 outLayoutParams.format = PixelFormat.OPAQUE; 62 outLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG; 63 outLayoutParams.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; 64 } 65 66 @Override updateUi(String groupName, int groupCount, int groupIndex, Icon icon, CharSequence message, boolean showDoNotAsk)67 public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon, 68 CharSequence message, boolean showDoNotAsk) { 69 if (Log.isLoggable(TAG, Log.DEBUG)) { 70 Log.d(TAG, "updateUi() - groupName: " + groupName 71 + ", groupCount: " + groupCount 72 + ", groupIndex: " + groupIndex 73 + ", icon: " + icon 74 + ", message: " + message 75 + ", showDoNotAsk: " + showDoNotAsk); 76 } 77 78 mGroupName = groupName; 79 mShowDoNotAsk = showDoNotAsk; 80 mMessage = message; 81 mIcon = icon; 82 mCurrentPageText = (groupCount > 1 ? 83 mContext.getString(R.string.current_permission_template, groupIndex + 1, groupCount) 84 : null); 85 86 invalidate(); 87 } 88 89 @Override saveInstanceState(Bundle outState)90 public void saveInstanceState(Bundle outState) { 91 outState.putString(ARG_GROUP_NAME, mGroupName); 92 } 93 94 @Override loadInstanceState(Bundle savedInstanceState)95 public void loadInstanceState(Bundle savedInstanceState) { 96 mGroupName = savedInstanceState.getString(ARG_GROUP_NAME); 97 } 98 99 @Override onBackPressed()100 public void onBackPressed() { 101 if (mResultListener != null) { 102 mResultListener.onPermissionGrantResult(mGroupName, false, false); 103 } 104 } 105 106 @Override // ConfirmationViewHandler onButton1()107 public void onButton1() { 108 onClick(true /* granted */, false /* doNotAskAgain */); 109 } 110 111 @Override // ConfirmationViewHandler onButton2()112 public void onButton2() { 113 onClick(false /* granted */, false /* doNotAskAgain */); 114 } 115 116 @Override // ConfirmationViewHandler onButton3()117 public void onButton3() { 118 onClick(false /* granted */, true /* doNotAskAgain */); 119 } 120 121 @Override // ConfirmationViewHandler getCurrentPageText()122 public CharSequence getCurrentPageText() { 123 return mCurrentPageText; 124 } 125 126 @Override // ConfirmationViewHandler getPermissionIcon()127 public Icon getPermissionIcon() { 128 return mIcon; 129 } 130 131 @Override // ConfirmationViewHandler getMessage()132 public CharSequence getMessage() { 133 return mMessage; 134 } 135 136 @Override // ConfirmationViewHandler getButtonBarMode()137 public int getButtonBarMode() { 138 return mShowDoNotAsk ? MODE_VERTICAL_BUTTONS : MODE_HORIZONTAL_BUTTONS; 139 } 140 141 @Override // ConfirmationViewHandler getVerticalButton1Text()142 public CharSequence getVerticalButton1Text() { 143 return mContext.getString(R.string.grant_dialog_button_allow); 144 } 145 146 @Override // ConfirmationViewHandler getVerticalButton2Text()147 public CharSequence getVerticalButton2Text() { 148 return mContext.getString(R.string.grant_dialog_button_deny); 149 } 150 151 @Override // ConfirmationViewHandler getVerticalButton3Text()152 public CharSequence getVerticalButton3Text() { 153 return mContext.getString(R.string.grant_dialog_button_deny_dont_ask_again); 154 } 155 156 @Override // ConfirmationViewHandler getVerticalButton1Icon()157 public Drawable getVerticalButton1Icon(){ 158 return mContext.getDrawable(R.drawable.confirm_button); 159 } 160 161 @Override // ConfirmationViewHandler getVerticalButton2Icon()162 public Drawable getVerticalButton2Icon(){ 163 return mContext.getDrawable(R.drawable.cancel_button); 164 } 165 166 @Override // ConfirmationViewHandler getVerticalButton3Icon()167 public Drawable getVerticalButton3Icon(){ 168 return mContext.getDrawable(R.drawable.deny_button); 169 } 170 onClick(boolean granted, boolean doNotAskAgain)171 private void onClick(boolean granted, boolean doNotAskAgain) { 172 if (mResultListener != null) { 173 mResultListener.onPermissionGrantResult(mGroupName, granted, doNotAskAgain); 174 } 175 } 176 } 177