diff options
11 files changed, 251 insertions, 152 deletions
diff --git a/PermissionController/res/layout/grant_permissions.xml b/PermissionController/res/layout/grant_permissions.xml index d6c3ec66e..03d657385 100644 --- a/PermissionController/res/layout/grant_permissions.xml +++ b/PermissionController/res/layout/grant_permissions.xml @@ -77,11 +77,6 @@ style="@style/PermissionGrantButtonAllowForeground" /> <Button - android:id="@+id/permission_allow_always_button" - android:text="@string/grant_dialog_button_allow_always" - style="@style/PermissionGrantButtonAllowAlways" /> - - <Button android:id="@+id/permission_deny_button" android:text="@string/grant_dialog_button_deny" style="@style/PermissionGrantButtonDeny" /> @@ -90,6 +85,16 @@ android:id="@+id/permission_deny_and_dont_ask_again_button" android:text="@string/grant_dialog_button_deny" style="@style/PermissionGrantButtonDeny" /> + + <Button + android:id="@+id/permission_no_upgrade_button" + android:text="@string/grant_dialog_button_no_upgrade" + style="@style/PermissionGrantButtonNoUpgrade" /> + + <Button + android:id="@+id/permission_no_upgrade_and_dont_ask_again_button" + android:text="@string/grant_dialog_button_no_upgrade" + style="@style/PermissionGrantButtonNoUpgrade" /> </LinearLayout> </LinearLayout> diff --git a/PermissionController/res/values/overlayable.xml b/PermissionController/res/values/overlayable.xml index c3a6d5070..328330742 100644 --- a/PermissionController/res/values/overlayable.xml +++ b/PermissionController/res/values/overlayable.xml @@ -41,9 +41,9 @@ <item type="style" name="PermissionGrantButtonBarSpace" /> <item type="style" name="PermissionGrantButton" /> <item type="style" name="PermissionGrantButtonAllow" /> - <item type="style" name="PermissionGrantButtonAllowAlways" /> <item type="style" name="PermissionGrantButtonAllowForeground" /> <item type="style" name="PermissionGrantButtonDeny" /> + <item type="style" name="PermissionGrantButtonNoUpgrade" /> <!-- END PERMISSION GRANT DIALOG --> diff --git a/PermissionController/res/values/strings.xml b/PermissionController/res/values/strings.xml index 0bc2cbab1..94fb6f500 100644 --- a/PermissionController/res/values/strings.xml +++ b/PermissionController/res/values/strings.xml @@ -37,10 +37,7 @@ <string name="grant_dialog_button_deny_and_dont_ask_again">Deny \u0026 don\u2019t ask again</string> <!-- Title for the dialog button to deny a change from foreground to background permission grant. [CHAR LIMIT=60] --> - <string name="grant_dialog_button_deny_background">Keep while-in-use access</string> - - <!-- Title for the dialog button to always deny a change from foreground to background permission grant from now on. [CHAR LIMIT=60] --> - <string name="grant_dialog_button_deny_background_and_dont_ask_again">Keep and don\u2019t ask again</string> + <string name="grant_dialog_button_no_upgrade">Keep \u201cWhile the app is in use\u201d</string> <!-- Title for the dialog button to get more info about a permission. [CHAR LIMIT=15] --> <string name="grant_dialog_button_more_info">More info</string> @@ -870,4 +867,6 @@ Allow <xliff:g id="app_name" example="Gmail">%4$s</xliff:g> to upload a bug repo <!-- Message shown to the user when the apps requests permission from this group. Shows in the isolated storage case. If ever possible this should stay below 80 characters (assuming the parameters takes 20 characters). Don't abbreviate until the message reaches 120 characters though. [CHAR LIMIT=120] --> <string name="permgrouprequest_storage_isolated">Allow <b><xliff:g id="app_name" example="Gmail">%1$s</xliff:g></b> to access photos and media on your device?</string> + <!-- Subtitle of the message shown to the user when the apps requests permission to use the location while app is in foreground and background. Try to keep the link annotation at the end of the string [CHAR LIMIT=150] --> + <string name="permgroupupgraderequestdeail_location">This wants to access your location all the time, even when you\u2019re not using the app. Allow in <annotation id="link">settings</annotation>.</string> </resources> diff --git a/PermissionController/res/values/styles.xml b/PermissionController/res/values/styles.xml index bcd3531ab..b846c84a5 100644 --- a/PermissionController/res/values/styles.xml +++ b/PermissionController/res/values/styles.xml @@ -104,14 +104,14 @@ <!-- for use in overlays --> <style name="PermissionGrantButtonAllow" parent="@style/PermissionGrantButton"></style> - <style name="PermissionGrantButtonAllowAlways" - parent="@style/PermissionGrantButton"></style> <style name="PermissionGrantButtonAllowForeground" parent="@style/PermissionGrantButton"></style> <style name="PermissionGrantButtonAllowOneTime" parent="@style/PermissionGrantButton"></style> <style name="PermissionGrantButtonDeny" parent="@style/PermissionGrantButton"></style> + <style name="PermissionGrantButtonNoUpgrade" + parent="@style/PermissionGrantButton"></style> <!-- END PERMISSION GRANT DIALOG --> diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/AppPermissionActivity.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/AppPermissionActivity.java index 18ab04d10..2a66ba9e6 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/AppPermissionActivity.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/AppPermissionActivity.java @@ -51,6 +51,9 @@ public final class AppPermissionActivity extends FragmentActivity { public static final String EXTRA_CALLER_NAME = "com.android.permissioncontroller.extra.CALLER_NAME"; + public static final String EXTRA_RESULT_PERMISSION_INTERACTED = "com.android" + + ".permissioncontroller.extra.RESULT_PERMISSION_INTERACTED"; + @Override public void onCreate(Bundle savedInstanceState) { if (DeviceUtils.isAuto(this)) { diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsActivity.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsActivity.java index 6d36c776e..c8061e197 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsActivity.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsActivity.java @@ -38,6 +38,7 @@ import static com.android.permissioncontroller.permission.ui.GrantPermissionsVie import static com.android.permissioncontroller.permission.ui.GrantPermissionsViewHandler.GRANTED_ONE_TIME; import static com.android.permissioncontroller.permission.utils.Utils.getRequestMessage; +import android.Manifest; import android.app.Activity; import android.app.KeyguardManager; import android.app.admin.DevicePolicyManager; @@ -51,9 +52,12 @@ import android.os.Build; import android.os.Bundle; import android.os.UserHandle; import android.permission.PermissionManager; -import android.text.Html; +import android.text.Annotation; +import android.text.SpannableString; import android.text.Spanned; +import android.text.style.ClickableSpan; import android.util.ArrayMap; +import android.util.ArraySet; import android.util.Log; import android.util.Pair; import android.view.MotionEvent; @@ -88,23 +92,29 @@ public class GrantPermissionsActivity extends Activity private static final String KEY_REQUEST_ID = GrantPermissionsActivity.class.getName() + "_REQUEST_ID"; + public static final String ANNOTATION_ID = "link"; - public static int NUM_BUTTONS = 6; - public static int LABEL_ALLOW_BUTTON = 0; - public static int LABEL_ALLOW_ALWAYS_BUTTON = 1; - public static int LABEL_ALLOW_FOREGROUND_BUTTON = 2; - public static int LABEL_DENY_BUTTON = 3; - public static int LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON = 4; - public static int LABEL_ALLOW_ONE_TIME = 5; + public static final int NUM_BUTTONS = 8; + public static final int VISIBILITY_ALLOW_BUTTON = 0; + // public static int LABEL_ALLOW_ALWAYS_BUTTON = 1; RESERVED + public static final int VISIBILITY_ALLOW_FOREGROUND_BUTTON = 2; + public static final int VISIBILITY_DENY_BUTTON = 3; + public static final int VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON = 4; + public static final int VISIBILITY_ALLOW_ONE_TIME_BUTTON = 5; + public static final int VISIBILITY_NO_UPGRADE_BUTTON = 6; + public static final int VISIBILITY_NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON = 7; + + private static final int APP_PERMISSION_REQUEST_CODE = 1; /** Unique Id of a request */ private long mRequestId; private String[] mRequestedPermissions; - private CharSequence[] mButtonLabels; + private boolean[] mButtonVisibilities; private ArrayMap<Pair<String, Boolean>, GroupState> mRequestGrantPermissionGroups = new ArrayMap<>(); + private ArraySet<String> mPermissionGroupsToSkip = new ArraySet<>(); private GrantPermissionsViewHandler mViewHandler; private AppPermissions mAppPermissions; @@ -502,6 +512,14 @@ public class GrantPermissionsActivity extends Activity } @Override + protected void onResume() { + if (!showNextPermissionGroupGrantRequest()) { + setResultAndFinish(); + } + super.onResume(); + } + + @Override protected void onStop() { super.onStop(); @@ -585,7 +603,7 @@ public class GrantPermissionsActivity extends Activity return false; } - return true; + return !mPermissionGroupsToSkip.contains(groupState.mGroup.getName()); } private boolean showNextPermissionGroupGrantRequest() { @@ -599,10 +617,8 @@ public class GrantPermissionsActivity extends Activity int currentIndex = 0; List<GroupState> groupStates = new ArrayList<>(mRequestGrantPermissionGroups.values()); - Collections.sort(groupStates, (s1, s2) -> { - return -Boolean.compare(s1.mGroup.supportsOneTimeGrant(), - s2.mGroup.supportsOneTimeGrant()); - }); + Collections.sort(groupStates, (s1, s2) -> -Boolean.compare(s1.mGroup.supportsOneTimeGrant(), + s2.mGroup.supportsOneTimeGrant())); for (GroupState groupState : groupStates) { if (!shouldShowRequestForGroupState(groupState)) { continue; @@ -652,59 +668,75 @@ public class GrantPermissionsActivity extends Activity } } - // The button doesn't show when its label is null - mButtonLabels = new CharSequence[NUM_BUTTONS]; - mButtonLabels[LABEL_ALLOW_BUTTON] = getString(R.string.grant_dialog_button_allow); - mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON] = null; - mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] = null; - mButtonLabels[LABEL_ALLOW_ONE_TIME] = null; - mButtonLabels[LABEL_DENY_BUTTON] = getString(R.string.grant_dialog_button_deny); - if (isForegroundPermissionUserSet || isBackgroundPermissionUserSet) { - mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] = - getString(R.string.grant_dialog_button_deny); - mButtonLabels[LABEL_DENY_BUTTON] = null; - } else { - mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] = null; - } + mButtonVisibilities = new boolean[NUM_BUTTONS]; + mButtonVisibilities[VISIBILITY_ALLOW_BUTTON] = true; + mButtonVisibilities[VISIBILITY_DENY_BUTTON] = true; + mButtonVisibilities[VISIBILITY_ALLOW_ONE_TIME_BUTTON] = + groupState.mGroup.supportsOneTimeGrant(); - if (groupState.mGroup.supportsOneTimeGrant()) { - mButtonLabels[LABEL_ALLOW_ONE_TIME] = - getString(R.string.grant_dialog_button_allow_one_time); - } int messageId; int detailMessageId = 0; - if (needForegroundPermission) { - messageId = groupState.mGroup.getRequest(); - - if (groupState.mGroup.hasPermissionWithBackgroundMode()) { - mButtonLabels[LABEL_ALLOW_BUTTON] = null; - mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON] = - getString(R.string.grant_dialog_button_allow_foreground); - mButtonLabels[LABEL_ALLOW_ONE_TIME] = getString( - R.string.grant_dialog_button_allow_one_time); - if (needBackgroundPermission) { - mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON] = - getString(R.string.grant_dialog_button_allow_always); - if (isForegroundPermissionUserSet || isBackgroundPermissionUserSet) { - mButtonLabels[LABEL_DENY_BUTTON] = null; - } - } + + // TODO evanseverson: R ui not implemented yet, just show them Q- for now + // STOPSHIP + if (mAppPermissions.getPackageInfo().applicationInfo.targetSdkVersion + >= Build.VERSION_CODES.R && false) { + if (needForegroundPermission && needBackgroundPermission) { + Log.e(LOG_TAG, "Apps targeting sdk " + Build.VERSION_CODES.R + + " or later must get foreground permission" + + " before requesting background"); + return false; + } else if (needForegroundPermission) { + // Show (onetime), foreground, deny + } else if (needBackgroundPermission) { + // Go to AppPermission page if rate limit hasn't been reached } else { - detailMessageId = groupState.mGroup.getRequestDetail(); + // Not reached as the permissions should be auto-granted + return false; } } else { - if (needBackgroundPermission) { - messageId = groupState.mGroup.getBackgroundRequest(); - detailMessageId = groupState.mGroup.getBackgroundRequestDetail(); - mButtonLabels[LABEL_ALLOW_BUTTON] = - getString(R.string.grant_dialog_button_allow_background); - mButtonLabels[LABEL_ALLOW_ONE_TIME] = null; - mButtonLabels[LABEL_DENY_BUTTON] = null; - mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] = - getString(R.string.grant_dialog_button_deny_background); + if (groupState.mGroup.hasPermissionWithBackgroundMode() + || groupState.mGroup.isBackgroundGroup()) { // is tristate + if (needForegroundPermission && needBackgroundPermission) { + // Requests both background and foreground + messageId = groupState.mGroup.getRequest(); + detailMessageId = groupState.mGroup.getBackgroundRequestDetail(); + mButtonVisibilities[VISIBILITY_ALLOW_BUTTON] = false; + mButtonVisibilities[VISIBILITY_ALLOW_FOREGROUND_BUTTON] = true; + mButtonVisibilities[VISIBILITY_DENY_BUTTON] = + !isForegroundPermissionUserSet; + mButtonVisibilities[VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON] = + isForegroundPermissionUserSet; + } else if (needForegroundPermission) { + // Only requests foreground + messageId = groupState.mGroup.getRequest(); + mButtonVisibilities[VISIBILITY_ALLOW_BUTTON] = false; + mButtonVisibilities[VISIBILITY_ALLOW_FOREGROUND_BUTTON] = true; + mButtonVisibilities[VISIBILITY_DENY_BUTTON] = + !isForegroundPermissionUserSet; + mButtonVisibilities[VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON] = + isForegroundPermissionUserSet; + } else if (needBackgroundPermission) { + // Upgrade from foreground to background + messageId = groupState.mGroup.getBackgroundRequest(); + detailMessageId = groupState.mGroup.getBackgroundRequestDetail(); + mButtonVisibilities[VISIBILITY_ALLOW_BUTTON] = false; + mButtonVisibilities[VISIBILITY_DENY_BUTTON] = false; + mButtonVisibilities[VISIBILITY_ALLOW_ONE_TIME_BUTTON] = false; + mButtonVisibilities[VISIBILITY_NO_UPGRADE_BUTTON] = + !isBackgroundPermissionUserSet; + mButtonVisibilities[VISIBILITY_NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON] = + isBackgroundPermissionUserSet; + } else { + // Not reached as the permissions should be auto-granted + return false; + } } else { - // Not reached as the permissions should be auto-granted - return false; + messageId = groupState.mGroup.getRequest(); + mButtonVisibilities[VISIBILITY_DENY_BUTTON] = + !isForegroundPermissionUserSet; + mButtonVisibilities[VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON] = + isForegroundPermissionUserSet; } } @@ -714,10 +746,32 @@ public class GrantPermissionsActivity extends Activity Spanned detailMessage = null; if (detailMessageId != 0) { try { - detailMessage = Html.fromHtml( - getPackageManager().getResourcesForApplication( - groupState.mGroup.getDeclaringPackage()).getString( - detailMessageId), 0); + detailMessage = + new SpannableString(getPackageManager().getResourcesForApplication( + groupState.mGroup.getDeclaringPackage()).getText( + detailMessageId)); + if (Manifest.permission_group.LOCATION.equals(groupState.mGroup.getName()) + && needBackgroundPermission && !needForegroundPermission) { + // TODO evanseverson: new requestDetail field to add in frameworks + detailMessage = new SpannableString( + getText(R.string.permgroupupgraderequestdeail_location)); + } + Annotation[] annotations = detailMessage.getSpans( + 0, detailMessage.length(), Annotation.class); + int numAnnotations = annotations.length; + for (int i = 0; i < numAnnotations; i++) { + Annotation annotation = annotations[i]; + if (annotation.getValue().equals(ANNOTATION_ID)) { + int start = detailMessage.getSpanStart(annotation); + int end = detailMessage.getSpanEnd(annotation); + ClickableSpan clickableSpan = getLinkToAppPermissions(groupState); + SpannableString spannableString = + new SpannableString(detailMessage); + spannableString.setSpan(clickableSpan, start, end, 0); + detailMessage = spannableString; + break; + } + } } catch (NameNotFoundException ignored) { } } @@ -726,7 +780,7 @@ public class GrantPermissionsActivity extends Activity setTitle(message); mViewHandler.updateUi(groupState.mGroup.getName(), numGrantRequests, currentIndex, - icon, message, detailMessage, mButtonLabels); + icon, message, detailMessage, mButtonVisibilities); return true; } @@ -739,6 +793,37 @@ public class GrantPermissionsActivity extends Activity return false; } + private ClickableSpan getLinkToAppPermissions(GroupState groupState) { + return new ClickableSpan() { + @Override + public void onClick(View widget) { + Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION); + intent.putExtra(Intent.EXTRA_PACKAGE_NAME, + mAppPermissions.getPackageInfo().packageName); + intent.putExtra(Intent.EXTRA_PERMISSION_GROUP_NAME, + groupState.mGroup.getName()); + intent.putExtra(Intent.EXTRA_USER, groupState.mGroup.getUser()); + intent.putExtra(AppPermissionActivity.EXTRA_CALLER_NAME, + GrantPermissionsActivity.class.getName()); + intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + startActivityForResult(intent, APP_PERMISSION_REQUEST_CODE); + } + }; + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == APP_PERMISSION_REQUEST_CODE) { + if (data != null) { + String groupName = data.getStringExtra( + AppPermissionActivity.EXTRA_RESULT_PERMISSION_INTERACTED); + if (groupName != null) { + mPermissionGroupsToSkip.add(groupName); + } + } + } + } + @Override public void onPermissionGrantResult(String name, @GrantPermissionsViewHandler.Result int result) { @@ -995,23 +1080,16 @@ public class GrantPermissionsActivity extends Activity int presentedButtons = getButtonState(); switch (grantResult) { case GRANTED_ALWAYS: - if ((presentedButtons & (1 << LABEL_ALLOW_BUTTON)) != 0) { - clickedButton = 1 << LABEL_ALLOW_BUTTON; - } else { - clickedButton = 1 << LABEL_ALLOW_ALWAYS_BUTTON; - } + clickedButton = 1 << VISIBILITY_ALLOW_BUTTON; break; case GRANTED_FOREGROUND_ONLY: - clickedButton = 1 << LABEL_ALLOW_FOREGROUND_BUTTON; + clickedButton = 1 << VISIBILITY_ALLOW_FOREGROUND_BUTTON; break; case DENIED: - clickedButton = 1 << LABEL_DENY_BUTTON; - break; - case DENIED_DO_NOT_ASK_AGAIN: - clickedButton = 1 << LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON; + clickedButton = 1 << VISIBILITY_DENY_BUTTON; break; case GRANTED_ONE_TIME: - clickedButton = 1 << LABEL_ALLOW_ONE_TIME; + clickedButton = 1 << VISIBILITY_ALLOW_ONE_TIME_BUTTON; default: break; } @@ -1025,13 +1103,13 @@ public class GrantPermissionsActivity extends Activity } private int getButtonState() { - if (mButtonLabels == null) { + if (mButtonVisibilities == null) { return 0; } int buttonState = 0; for (int i = NUM_BUTTONS - 1; i >= 0; i--) { buttonState *= 2; - if (mButtonLabels[i] != null) { + if (mButtonVisibilities[i]) { buttonState++; } } diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsViewHandler.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsViewHandler.java index 6daf62e8f..e76ca76c2 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsViewHandler.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsViewHandler.java @@ -77,10 +77,10 @@ public interface GrantPermissionsViewHandler { * @param message the message to display the user * @param detailMessage another message to display to the user. This clarifies "message" in more * detail - * @param buttonLabels labels for each button. Use null to make the button gone + * @param buttonVisibilities visibilities for each button */ void updateUi(String groupName, int groupCount, int groupIndex, Icon icon, - CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels); + CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities); /** * Sets the result listener that will be notified when the user responds diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsWatchViewHandler.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsWatchViewHandler.java index a34eae21b..6d521af35 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsWatchViewHandler.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/GrantPermissionsWatchViewHandler.java @@ -1,6 +1,6 @@ package com.android.permissioncontroller.permission.ui; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON; import android.app.AlertDialog; import android.app.Dialog; @@ -79,11 +79,10 @@ final class GrantPermissionsWatchViewHandler implements GrantPermissionsViewHand @Override public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon, - CharSequence message, CharSequence detailMessage, - CharSequence[] buttonLabels) { + CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities) { // TODO: Handle detailMessage - boolean showDoNotAsk = buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] != null; + boolean showDoNotAsk = buttonVisibilities[VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON]; if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "updateUi() - groupName: " + groupName diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/AppPermissionFragment.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/AppPermissionFragment.java index a1fdc7fc5..3eaad5b76 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/AppPermissionFragment.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/AppPermissionFragment.java @@ -20,6 +20,7 @@ import static com.android.permissioncontroller.Constants.EXTRA_SESSION_ID; import static com.android.permissioncontroller.Constants.INVALID_SESSION_ID; import android.app.ActionBar; +import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; @@ -215,14 +216,22 @@ public class AppPermissionFragment extends SettingsWithLargeHeader { return; } - mAlwaysButton.setOnClickListener((v) -> mViewModel.requestChange(true, this, - ChangeTarget.CHANGE_BOTH)); + mAlwaysButton.setOnClickListener((v) -> { + mViewModel.requestChange(true, this, ChangeTarget.CHANGE_BOTH); + getActivity().setResult(Activity.RESULT_OK, new Intent().putExtra( + AppPermissionActivity.EXTRA_RESULT_PERMISSION_INTERACTED, mPermGroupName)); + }); mForegroundOnlyButton.setOnClickListener((v) -> { mViewModel.requestChange(true, this, ChangeTarget.CHANGE_FOREGROUND); mViewModel.requestChange(false, this, ChangeTarget.CHANGE_BACKGROUND); + getActivity().setResult(Activity.RESULT_OK, new Intent().putExtra( + AppPermissionActivity.EXTRA_RESULT_PERMISSION_INTERACTED, mPermGroupName)); + }); + mDenyButton.setOnClickListener((v) -> { + mViewModel.requestChange(false, this, ChangeTarget.CHANGE_BOTH); + getActivity().setResult(Activity.RESULT_OK, new Intent().putExtra( + AppPermissionActivity.EXTRA_RESULT_PERMISSION_INTERACTED, mPermGroupName)); }); - mDenyButton.setOnClickListener((v) -> mViewModel.requestChange(false, this, - ChangeTarget.CHANGE_BOTH)); setButtonState(mAlwaysButton, states.get(0), true); setButtonState(mForegroundOnlyButton, states.get(1), false); diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java index ce624a708..4ed8ddfb8 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/handheld/GrantPermissionsViewHandlerImpl.java @@ -16,18 +16,20 @@ package com.android.permissioncontroller.permission.ui.handheld; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_ALWAYS_BUTTON; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_BUTTON; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_FOREGROUND_BUTTON; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_ALLOW_ONE_TIME; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_DENY_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_ALLOW_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_ALLOW_FOREGROUND_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_ALLOW_ONE_TIME_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_DENY_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_NO_UPGRADE_BUTTON; import android.app.Activity; import android.content.Intent; import android.graphics.drawable.Icon; import android.os.Bundle; import android.os.UserHandle; +import android.text.method.LinkMovementMethod; import android.transition.ChangeBounds; import android.transition.TransitionManager; import android.view.LayoutInflater; @@ -56,7 +58,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand public static final String ARG_GROUP_ICON = "ARG_GROUP_ICON"; public static final String ARG_GROUP_MESSAGE = "ARG_GROUP_MESSAGE"; private static final String ARG_GROUP_DETAIL_MESSAGE = "ARG_GROUP_DETAIL_MESSAGE"; - private static final String ARG_DIALOG_BUTTON_LABELS = "ARG_DIALOG_BUTTON_LABELS"; + private static final String ARG_DIALOG_BUTTON_VISIBILITIES = "ARG_DIALOG_BUTTON_VISIBILITIES"; // Animation parameters. private static final long SWITCH_TIME_MILLIS = 75; @@ -75,18 +77,19 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand private Icon mGroupIcon; private CharSequence mGroupMessage; private CharSequence mDetailMessage; - private CharSequence[] mButtonLabels; + private boolean[] mButtonVisibilities; // Views private ImageView mIconView; private TextView mMessageView; private TextView mDetailMessageView; private Button mAllowButton; - private Button mAllowAlwaysButton; private Button mAllowForegroundButton; private Button mAllowOneTimeButton; private Button mDenyButton; private Button mDenyAndDontAskAgainButton; + private Button mNoUpgradeButton; + private Button mNoUpgradeAndDontAskAgainButton; private ViewGroup mRootView; public GrantPermissionsViewHandlerImpl(Activity activity, String appPackageName, @@ -110,8 +113,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand arguments.putParcelable(ARG_GROUP_ICON, mGroupIcon); arguments.putCharSequence(ARG_GROUP_MESSAGE, mGroupMessage); arguments.putCharSequence(ARG_GROUP_DETAIL_MESSAGE, mDetailMessage); - arguments.putCharSequenceArray(ARG_DIALOG_BUTTON_LABELS, mButtonLabels); - + arguments.putBooleanArray(ARG_DIALOG_BUTTON_VISIBILITIES, mButtonVisibilities); } @Override @@ -122,14 +124,14 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand mGroupCount = savedInstanceState.getInt(ARG_GROUP_COUNT); mGroupIndex = savedInstanceState.getInt(ARG_GROUP_INDEX); mDetailMessage = savedInstanceState.getCharSequence(ARG_GROUP_DETAIL_MESSAGE); - mButtonLabels = savedInstanceState.getCharSequenceArray(ARG_DIALOG_BUTTON_LABELS); + mButtonVisibilities = savedInstanceState.getBooleanArray(ARG_DIALOG_BUTTON_VISIBILITIES); updateAll(); } @Override public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon, - CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels) { + CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities) { boolean isNewGroup = mGroupIndex != groupIndex; mGroupName = groupName; @@ -138,7 +140,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand mGroupIcon = icon; mGroupMessage = message; mDetailMessage = detailMessage; - mButtonLabels = buttonLabels; + mButtonVisibilities = buttonVisibilities; // If this is a second (or later) permission and the views exist, then animate. if (mIconView != null) { @@ -170,26 +172,28 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand mRootView.findViewById(R.id.grant_singleton).setOnClickListener(this); // Cancel dialog mRootView.findViewById(R.id.grant_dialog).setOnClickListener(this); // Swallow click event - mMessageView = (TextView) mRootView.findViewById(R.id.permission_message); - mDetailMessageView = (TextView) mRootView.findViewById(R.id.detail_message); - mIconView = (ImageView) mRootView.findViewById(R.id.permission_icon); - mAllowButton = (Button) mRootView.findViewById(R.id.permission_allow_button); + mMessageView = mRootView.findViewById(R.id.permission_message); + mDetailMessageView = mRootView.findViewById(R.id.detail_message); + mDetailMessageView.setMovementMethod(LinkMovementMethod.getInstance()); + mIconView = mRootView.findViewById(R.id.permission_icon); + mAllowButton = mRootView.findViewById(R.id.permission_allow_button); mAllowButton.setOnClickListener(this); - mAllowAlwaysButton = (Button) mRootView.findViewById(R.id.permission_allow_always_button); - mAllowAlwaysButton.setOnClickListener(this); mAllowForegroundButton = - (Button) mRootView.findViewById(R.id.permission_allow_foreground_only_button); + mRootView.findViewById(R.id.permission_allow_foreground_only_button); mAllowForegroundButton.setOnClickListener(this); mAllowOneTimeButton = - (Button) mRootView.findViewById(R.id.permission_allow_one_time_button); + mRootView.findViewById(R.id.permission_allow_one_time_button); mAllowOneTimeButton.setOnClickListener(this); - mDenyButton = (Button) mRootView.findViewById(R.id.permission_deny_button); + mDenyButton = mRootView.findViewById(R.id.permission_deny_button); mDenyButton.setOnClickListener(this); mDenyAndDontAskAgainButton = - (Button) mRootView.findViewById(R.id.permission_deny_and_dont_ask_again_button); + mRootView.findViewById(R.id.permission_deny_and_dont_ask_again_button); mDenyAndDontAskAgainButton.setOnClickListener(this); - - mRootView.findViewById(R.id.permission_deny_button).setOnClickListener(this); + mNoUpgradeButton = mRootView.findViewById(R.id.permission_no_upgrade_button); + mNoUpgradeButton.setOnClickListener(this); + mNoUpgradeAndDontAskAgainButton = + mRootView.findViewById(R.id.permission_no_upgrade_and_dont_ask_again_button); + mNoUpgradeAndDontAskAgainButton.setOnClickListener(this); if (mGroupName != null) { updateAll(); @@ -220,22 +224,18 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand } private void updateButtons() { - updateButton(mAllowButton, mButtonLabels[LABEL_ALLOW_BUTTON]); - updateButton(mAllowAlwaysButton, mButtonLabels[LABEL_ALLOW_ALWAYS_BUTTON]); - updateButton(mAllowForegroundButton, mButtonLabels[LABEL_ALLOW_FOREGROUND_BUTTON]); - updateButton(mAllowOneTimeButton, mButtonLabels[LABEL_ALLOW_ONE_TIME]); - updateButton(mDenyButton, mButtonLabels[LABEL_DENY_BUTTON]); - updateButton(mDenyAndDontAskAgainButton, - mButtonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON]); + updateButton(mAllowButton, VISIBILITY_ALLOW_BUTTON); + updateButton(mAllowForegroundButton, VISIBILITY_ALLOW_FOREGROUND_BUTTON); + updateButton(mAllowOneTimeButton, VISIBILITY_ALLOW_ONE_TIME_BUTTON); + updateButton(mDenyButton, VISIBILITY_DENY_BUTTON); + updateButton(mDenyAndDontAskAgainButton, VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON); + updateButton(mNoUpgradeButton, VISIBILITY_NO_UPGRADE_BUTTON); + updateButton(mNoUpgradeAndDontAskAgainButton, + VISIBILITY_NO_UPGRADE_AND_DONT_ASK_AGAIN_BUTTON); } - private void updateButton(Button button, CharSequence label) { - if (label == null) { - button.setVisibility(View.GONE); - } else { - button.setVisibility(View.VISIBLE); - button.setText(label); - } + private void updateButton(Button button, int pos) { + button.setVisibility(mButtonVisibilities[pos] ? View.VISIBLE : View.GONE); } @Override @@ -248,13 +248,6 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand mResultListener.onPermissionGrantResult(mGroupName, GRANTED_ALWAYS); } break; - case R.id.permission_allow_always_button: - if (mResultListener != null) { - view.performAccessibilityAction( - AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); - mResultListener.onPermissionGrantResult(mGroupName, GRANTED_ALWAYS); - } - break; case R.id.permission_allow_foreground_only_button: if (mResultListener != null) { view.performAccessibilityAction( @@ -281,8 +274,7 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand if (mResultListener != null) { view.performAccessibilityAction( AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); - mResultListener.onPermissionGrantResult(mGroupName, - DENIED_DO_NOT_ASK_AGAIN); + mResultListener.onPermissionGrantResult(mGroupName, DENIED_DO_NOT_ASK_AGAIN); } break; case R.id.permission_more_info_button: @@ -292,6 +284,20 @@ public class GrantPermissionsViewHandlerImpl implements GrantPermissionsViewHand intent.putExtra(ManagePermissionsActivity.EXTRA_ALL_PERMISSIONS, true); mActivity.startActivity(intent); break; + case R.id.permission_no_upgrade_button: + if (mResultListener != null) { + view.performAccessibilityAction( + AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); + mResultListener.onPermissionGrantResult(mGroupName, DENIED); + } + break; + case R.id.permission_no_upgrade_and_dont_ask_again_button: + if (mResultListener != null) { + view.performAccessibilityAction( + AccessibilityNodeInfo.ACTION_CLEAR_ACCESSIBILITY_FOCUS, null); + mResultListener.onPermissionGrantResult(mGroupName, DENIED_DO_NOT_ASK_AGAIN); + } + break; case R.id.grant_singleton: if (mResultListener != null) { mResultListener.onPermissionGrantResult(mGroupName, CANCELED); diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/television/GrantPermissionsViewHandlerImpl.java b/PermissionController/src/com/android/permissioncontroller/permission/ui/television/GrantPermissionsViewHandlerImpl.java index 077c90588..1f722b9dc 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/television/GrantPermissionsViewHandlerImpl.java +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/television/GrantPermissionsViewHandlerImpl.java @@ -1,6 +1,6 @@ package com.android.permissioncontroller.permission.ui.television; -import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON; +import static com.android.permissioncontroller.permission.ui.GrantPermissionsActivity.VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON; import android.content.Context; import android.graphics.PixelFormat; @@ -82,7 +82,7 @@ public final class GrantPermissionsViewHandlerImpl implements GrantPermissionsVi @Override public void updateUi(String groupName, int groupCount, int groupIndex, Icon icon, - CharSequence message, CharSequence detailMessage, CharSequence[] buttonLabels) { + CharSequence message, CharSequence detailMessage, boolean[] buttonVisibilities) { // TODO: Handle detailMessage mGroupName = groupName; @@ -94,7 +94,7 @@ public final class GrantPermissionsViewHandlerImpl implements GrantPermissionsVi } mHardDenyButton.setVisibility( - buttonLabels[LABEL_DENY_AND_DONT_ASK_AGAIN_BUTTON] != null ? View.VISIBLE + buttonVisibilities[VISIBILITY_DENY_AND_DONT_ASK_AGAIN_BUTTON] ? View.VISIBLE : View.GONE); if (groupCount > 1) { mCurrentGroupView.setVisibility(View.VISIBLE); |