From baf4f05387eb8d1a5a766a6776a90361032cb7fb Mon Sep 17 00:00:00 2001 From: Peter_Liang Date: Fri, 6 Mar 2020 23:33:27 +0800 Subject: [PATCH] Update the edit shortcut menu (4/n). 1.Popup the permission dialog to warn user when trigger service target. 2.Update strings Bug: 148989057 Test: manual test Change-Id: If2d72bb5a98ba5a4c284a5d9a32991ea38fbadd7 --- .../AccessibilityButtonChooserActivity.java | 75 ++++++++ core/res/res/drawable/ic_pan_tool.xml | 26 +++ .../{ic_delete_item.xml => ic_visibility.xml} | 4 +- ...lity_enable_service_encryption_warning.xml | 175 ++++++++++++++++++ core/res/res/values/strings.xml | 46 ++++- core/res/res/values/symbols.xml | 11 +- 6 files changed, 330 insertions(+), 7 deletions(-) create mode 100644 core/res/res/drawable/ic_pan_tool.xml rename core/res/res/drawable/{ic_delete_item.xml => ic_visibility.xml} (77%) create mode 100644 core/res/res/layout/accessibility_enable_service_encryption_warning.xml diff --git a/core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java b/core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java index 958a341ee56db..c40864131a2e6 100644 --- a/core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java +++ b/core/java/com/android/internal/app/AccessibilityButtonChooserActivity.java @@ -54,7 +54,9 @@ import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; +import android.os.storage.StorageManager; import android.provider.Settings; +import android.text.BidiFormatter; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -62,6 +64,7 @@ import android.view.Window; import android.view.accessibility.AccessibilityManager; import android.widget.AdapterView; import android.widget.BaseAdapter; +import android.widget.Button; import android.widget.CheckBox; import android.widget.ImageView; import android.widget.Switch; @@ -73,6 +76,7 @@ import com.android.internal.R; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Locale; /** * Activity used to display and persist a service or feature target for the Accessibility button. @@ -84,6 +88,7 @@ public class AccessibilityButtonChooserActivity extends Activity { private int mShortcutUserType; private final List mTargets = new ArrayList<>(); private AlertDialog mAlertDialog; + private AlertDialog mEnableDialog; private TargetAdapter mTargetAdapter; private AccessibilityButtonTarget mCurrentCheckedTarget; @@ -570,6 +575,18 @@ public class AccessibilityButtonChooserActivity extends Activity { private void onTargetChecked(AdapterView parent, View view, int position, long id) { mCurrentCheckedTarget = mTargets.get(position); + + if ((mCurrentCheckedTarget.getType() == TargetType.ACCESSIBILITY_SERVICE) + && !mCurrentCheckedTarget.isChecked()) { + mEnableDialog = new AlertDialog.Builder(this) + .setView(createEnableDialogContentView(this, mCurrentCheckedTarget, + this::onPermissionAllowButtonClicked, + this::onPermissionDenyButtonClicked)) + .create(); + mEnableDialog.show(); + return; + } + onTargetChecked(mCurrentCheckedTarget, !mCurrentCheckedTarget.isChecked()); } @@ -693,4 +710,62 @@ public class AccessibilityButtonChooserActivity extends Activity { final List requiredTargets = ams.getAccessibilityShortcutTargets(sShortcutType); return requiredTargets.contains(id); } + + private void onPermissionAllowButtonClicked(View view) { + if (mCurrentCheckedTarget.getFragmentType() != AccessibilityServiceFragmentType.LEGACY) { + updateValueToSettings(mCurrentCheckedTarget.getId(), /* checked= */ true); + } + onTargetChecked(mCurrentCheckedTarget, /* checked= */ true); + mEnableDialog.dismiss(); + } + + private void onPermissionDenyButtonClicked(View view) { + mEnableDialog.dismiss(); + } + + private static View createEnableDialogContentView(Context context, + AccessibilityButtonTarget target, View.OnClickListener allowListener, + View.OnClickListener denyListener) { + final LayoutInflater inflater = (LayoutInflater) context.getSystemService( + Context.LAYOUT_INFLATER_SERVICE); + + final View content = inflater.inflate( + R.layout.accessibility_enable_service_encryption_warning, /* root= */ null); + + final TextView encryptionWarningView = (TextView) content.findViewById( + R.id.accessibility_encryption_warning); + if (StorageManager.isNonDefaultBlockEncrypted()) { + final String text = context.getString( + R.string.accessibility_enable_service_encryption_warning, + getServiceName(context, target.getLabel())); + encryptionWarningView.setText(text); + encryptionWarningView.setVisibility(View.VISIBLE); + } else { + encryptionWarningView.setVisibility(View.GONE); + } + + final ImageView permissionDialogIcon = content.findViewById( + R.id.accessibility_permissionDialog_icon); + permissionDialogIcon.setImageDrawable(target.getDrawable()); + + final TextView permissionDialogTitle = content.findViewById( + R.id.accessibility_permissionDialog_title); + permissionDialogTitle.setText(context.getString(R.string.accessibility_enable_service_title, + getServiceName(context, target.getLabel()))); + + final Button permissionAllowButton = content.findViewById( + R.id.accessibility_permission_enable_allow_button); + final Button permissionDenyButton = content.findViewById( + R.id.accessibility_permission_enable_deny_button); + permissionAllowButton.setOnClickListener(allowListener); + permissionDenyButton.setOnClickListener(denyListener); + + return content; + } + + // Gets the service name and bidi wrap it to protect from bidi side effects. + private static CharSequence getServiceName(Context context, CharSequence label) { + final Locale locale = context.getResources().getConfiguration().getLocales().get(0); + return BidiFormatter.getInstance(locale).unicodeWrap(label); + } } diff --git a/core/res/res/drawable/ic_pan_tool.xml b/core/res/res/drawable/ic_pan_tool.xml new file mode 100644 index 0000000000000..c1a8549b21410 --- /dev/null +++ b/core/res/res/drawable/ic_pan_tool.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/core/res/res/drawable/ic_delete_item.xml b/core/res/res/drawable/ic_visibility.xml similarity index 77% rename from core/res/res/drawable/ic_delete_item.xml rename to core/res/res/drawable/ic_visibility.xml index 8a398a44635ec..1956241569997 100644 --- a/core/res/res/drawable/ic_delete_item.xml +++ b/core/res/res/drawable/ic_visibility.xml @@ -12,7 +12,7 @@ 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. - --> +--> diff --git a/core/res/res/layout/accessibility_enable_service_encryption_warning.xml b/core/res/res/layout/accessibility_enable_service_encryption_warning.xml new file mode 100644 index 0000000000000..4000516605927 --- /dev/null +++ b/core/res/res/layout/accessibility_enable_service_encryption_warning.xml @@ -0,0 +1,175 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +