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
This commit is contained in:
Peter_Liang
2020-03-06 23:33:27 +08:00
parent b6d9e4168e
commit baf4f05387
6 changed files with 330 additions and 7 deletions

View File

@@ -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<AccessibilityButtonTarget> 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<String> 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);
}
}

View File

@@ -0,0 +1,26 @@
<!--
Copyright (C) 2020 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M23,5.5V20c0,2.2 -1.8,4 -4,4h-7.3c-1.08,0 -2.1,-0.43 -2.85,-1.19L1,14.83c0,0 1.26,-1.23 1.3,-1.25c0.22,-0.19 0.49,-0.29 0.79,-0.29c0.22,0 0.42,0.06 0.6,0.16C3.73,13.46 8,15.91 8,15.91V4c0,-0.83 0.67,-1.5 1.5,-1.5S11,3.17 11,4v7h1V1.5C12,0.67 12.67,0 13.5,0S15,0.67 15,1.5V11h1V2.5C16,1.67 16.67,1 17.5,1S19,1.67 19,2.5V11h1V5.5C20,4.67 20.67,4 21.5,4S23,4.67 23,5.5z"
android:fillColor="#FFFFFF"/>
</vector>

View File

@@ -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.
-->
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
@@ -21,6 +21,6 @@
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2V7H6v12zM19,4h-3.5l-1,-1h-5l-1,1H5v2h14V4z"
android:pathData="M12,4.5C7,4.5 2.73,7.61 1,12c1.73,4.39 6,7.5 11,7.5s9.27,-3.11 11,-7.5c-1.73,-4.39 -6,-7.5 -11,-7.5zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"
android:fillColor="#FFFFFF"/>
</vector>

View File

@@ -0,0 +1,175 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2020 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.
-->
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textDirection="locale"
android:scrollbarStyle="outsideOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/accessibility_permissionDialog_icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/accessibility_permissionDialog_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="20sp"
android:textColor="?android:attr/textColorPrimary"
android:fontFamily="google-sans-medium"/>
<TextView
android:id="@+id/accessibility_encryption_warning"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textAlignment="viewStart"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/accessibility_permissionDialog_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="32dp"
android:text="@string/accessibility_service_warning_description"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:fontFamily="sans-serif"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/accessibility_controlScreen_icon"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginRight="12dp"
android:src="@android:drawable/ic_visibility"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/accessibility_controlScreen_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/accessibility_service_screen_control_title"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:fontFamily="sans-serif"/>
</LinearLayout>
<TextView
android:id="@+id/accessibility_controlScreen_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:paddingStart="30dp"
android:text="@string/accessibility_service_screen_control_description"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:fontFamily="sans-serif"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/accessibility_performAction_icon"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_marginEnd="12dp"
android:src="@android:drawable/ic_pan_tool"
android:scaleType="fitCenter"/>
<TextView
android:id="@+id/accessibility_performAction_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/accessibility_service_action_perform_title"
android:textSize="16sp"
android:textColor="?android:attr/textColorPrimary"
android:fontFamily="sans-serif"/>
</LinearLayout>
<TextView
android:id="@+id/accessibility_performAction_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:paddingStart="30dp"
android:text="@string/accessibility_service_action_perform_description"
android:textSize="14sp"
android:textColor="?android:attr/textColorSecondary"
android:fontFamily="sans-serif" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/chooser_row_divider"/>
<Button
android:id="@+id/accessibility_permission_enable_allow_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/accessibility_dialog_button_allow"
style="?attr/buttonBarPositiveButtonStyle"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/chooser_row_divider"/>
<Button
android:id="@+id/accessibility_permission_enable_deny_button"
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="?android:attr/selectableItemBackground"
android:text="@string/accessibility_dialog_button_deny"
style="?attr/buttonBarPositiveButtonStyle"/>
</LinearLayout>
</ScrollView>

View File

@@ -4403,18 +4403,58 @@
accessibility feature.
</string>
<!-- Title for a warning about security implications of enabling an accessibility
service. [CHAR LIMIT=NONE] -->
<string name="accessibility_enable_service_title">Allow
<xliff:g id="service" example="TalkBack">%1$s</xliff:g> to have full control of your
device?</string>
<!-- Warning that the device data will not be encrypted with password or PIN if
enabling an accessibility service and there is a secure lock setup. [CHAR LIMIT=NONE] -->
<string name="accessibility_enable_service_encryption_warning">If you turn on
<xliff:g id="service" example="TalkBack">%1$s</xliff:g>, your device won’t use your screen
lock to enhance data encryption.
</string>
<!-- Warning description that explains that it's appropriate for accessibility
services to have full control to help users with accessibility needs. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_warning_description">Full control is appropriate for apps
that help you with accessibility needs, but not for most apps.
</string>
<!-- Title for the screen control in accessibility dialog. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_screen_control_title">View and control screen</string>
<!-- Description for the screen control in accessibility dialog. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_screen_control_description">It can read all content on the
screen and display content over other apps.
</string>
<!-- Title for the action perform in accessibility dialog. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_action_perform_title">View and perform actions</string>
<!-- Description for the action perform in accessibility dialog. [CHAR LIMIT=NONE] -->
<string name="accessibility_service_action_perform_description">It can track your interactions
with an app or a hardware sensor, and interact with apps on your behalf.
</string>
<!-- String for the allow button in accessibility permission dialog. [CHAR LIMIT=10] -->
<string name="accessibility_dialog_button_allow">Allow</string>
<!-- String for the deny button in accessibility permission dialog. [CHAR LIMIT=10] -->
<string name="accessibility_dialog_button_deny">Deny</string>
<!-- Title for accessibility select shortcut menu dialog. [CHAR LIMIT=100] -->
<string name="accessibility_select_shortcut_menu_title">Tap the accessibility app you want to use</string>
<string name="accessibility_select_shortcut_menu_title">Tap a feature to start using it:</string>
<!-- Title for accessibility edit shortcut selection menu dialog, and dialog is triggered
from accessibility button. [CHAR LIMIT=100] -->
<string name="accessibility_edit_shortcut_menu_button_title">Choose apps you want to use with
<string name="accessibility_edit_shortcut_menu_button_title">Choose apps to use with the
accessibility button
</string>
<!-- Title for accessibility edit shortcut selection menu dialog, and dialog is triggered
from volume key shortcut. [CHAR LIMIT=100] -->
<string name="accessibility_edit_shortcut_menu_volume_title">Choose apps you want to use with
<string name="accessibility_edit_shortcut_menu_volume_title">Choose apps to use with the
volume key shortcut
</string>

View File

@@ -3242,6 +3242,15 @@
<java-symbol type="string" name="accessibility_edit_shortcut_menu_volume_title" />
<java-symbol type="string" name="accessibility_uncheck_legacy_item_warning" />
<java-symbol type="layout" name="accessibility_enable_service_encryption_warning" />
<java-symbol type="id" name="accessibility_permissionDialog_icon" />
<java-symbol type="id" name="accessibility_permissionDialog_title" />
<java-symbol type="id" name="accessibility_encryption_warning" />
<java-symbol type="id" name="accessibility_permission_enable_allow_button" />
<java-symbol type="id" name="accessibility_permission_enable_deny_button" />
<java-symbol type="string" name="accessibility_enable_service_title" />
<java-symbol type="string" name="accessibility_enable_service_encryption_warning" />
<!-- Accessibility Button -->
<java-symbol type="layout" name="accessibility_button_chooser_item" />
<java-symbol type="id" name="accessibility_button_target_checkbox" />
@@ -3256,8 +3265,6 @@
<java-symbol type="drawable" name="ic_accessibility_color_correction" />
<java-symbol type="drawable" name="ic_accessibility_magnification" />
<java-symbol type="drawable" name="ic_delete_item" />
<!-- com.android.internal.widget.RecyclerView -->
<java-symbol type="id" name="item_touch_helper_previous_elevation"/>
<java-symbol type="dimen" name="item_touch_helper_max_drag_scroll_per_frame"/>