From 49d20fa68e9f716de126f146c446f36c0d7105f3 Mon Sep 17 00:00:00 2001 From: Ayush Sharma Date: Fri, 13 Aug 2021 16:38:59 +0000 Subject: [PATCH 1/2] Fetch admin details if not present in Intent. Get admin package/user details if this info is not present in the intent(ACTION_SHOW_ADMIN_SUPPORT_DETAILS) received Bug: 192245204 Test: atest MixedDeviceOwnerTest#testCreateAdminSupportIntent atest MixedProfileOwnerTest#testCreateAdminSupportIntent atest MixedManagedProfileOwnerTest#testCreateAdminSupportIntent Change-Id: Idda6078a64c03588f0b786ebc79079198ab722fe Merged-In: Idda6078a64c03588f0b786ebc79079198ab722fe --- .../enterprise/ActionDisabledByAdminDialog.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java index ce7ad242056..c4bef25b1cc 100644 --- a/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java +++ b/src/com/android/settings/enterprise/ActionDisabledByAdminDialog.java @@ -58,11 +58,25 @@ public class ActionDisabledByAdminDialog extends Activity return admin; } admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN); + int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId()); + + Bundle adminDetails = null; + if (admin.component == null) { + DevicePolicyManager devicePolicyManager = getSystemService(DevicePolicyManager.class); + adminDetails = devicePolicyManager.getEnforcingAdminAndUserDetails(userId, + getRestrictionFromIntent(intent)); + if (adminDetails != null) { + admin.component = adminDetails.getParcelable( + DevicePolicyManager.EXTRA_DEVICE_ADMIN); + } + } if (intent.hasExtra(Intent.EXTRA_USER)) { admin.user = intent.getParcelableExtra(Intent.EXTRA_USER); } else { - int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId()); + if (adminDetails != null) { + userId = adminDetails.getInt(Intent.EXTRA_USER_ID, UserHandle.myUserId()); + } if (userId == UserHandle.USER_NULL) { admin.user = null; } else { From f25e8aa74c28053efa106eca29f31d8cbdd3bf10 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Thu, 2 Sep 2021 11:24:51 +0800 Subject: [PATCH 2/2] Add more info on the dialog of AllowBindAppWidgetActivity - Show the label of the bound widget on the dialog of the AllowBindAppWidgetActivity. Bug: 184676316 Test: manual test Change-Id: Idf1f73bc1cdb8ef9ce632bfe4722b1469a6b8531 Merged-In: Idf1f73bc1cdb8ef9ce632bfe4722b1469a6b8531 (cherry picked from commit 1564ef5ca1788554119a9c8c8968a6f04e2fd639) --- res/values/strings.xml | 2 +- .../settings/AllowBindAppWidgetActivity.java | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 22631417a4b..594de34ae15 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5197,7 +5197,7 @@ Create widget and allow access? - After you create the widget, %1$s can access all data it displays. + After you create the widget, the application can access everything displayed.\n\nApplication: %1$s\nWidget: %2$s\n Always allow %1$s to create widgets and access their data diff --git a/src/com/android/settings/AllowBindAppWidgetActivity.java b/src/com/android/settings/AllowBindAppWidgetActivity.java index e7f7a6af203..0272c83702e 100644 --- a/src/com/android/settings/AllowBindAppWidgetActivity.java +++ b/src/com/android/settings/AllowBindAppWidgetActivity.java @@ -19,6 +19,7 @@ package com.android.settings; import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; import android.appwidget.AppWidgetManager; +import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.content.DialogInterface; @@ -122,9 +123,12 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements return; } } + mAppWidgetManager = AppWidgetManager.getInstance(this); + final String widgetLabel = getWidgetLabel(); AlertController.AlertParams ap = mAlertParams; ap.mTitle = getString(R.string.allow_bind_app_widget_activity_allow_bind_title); - ap.mMessage = getString(R.string.allow_bind_app_widget_activity_allow_bind, label); + ap.mMessage = getString(R.string.allow_bind_app_widget_activity_allow_bind, label, + widgetLabel); ap.mPositiveButtonText = getString(R.string.create); ap.mNegativeButtonText = getString(android.R.string.cancel); ap.mPositiveButtonListener = this; @@ -133,18 +137,30 @@ public class AllowBindAppWidgetActivity extends AlertActivity implements (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); ap.mView = inflater.inflate(com.android.internal.R.layout.always_use_checkbox, null); mAlwaysUse = (CheckBox) ap.mView.findViewById(com.android.internal.R.id.alwaysUse); - mAlwaysUse.setText(getString(R.string.allow_bind_app_widget_activity_always_allow_bind, label)); + mAlwaysUse.setText( + getString(R.string.allow_bind_app_widget_activity_always_allow_bind, label)); mAlwaysUse.setPadding(mAlwaysUse.getPaddingLeft(), mAlwaysUse.getPaddingTop(), mAlwaysUse.getPaddingRight(), (int) (mAlwaysUse.getPaddingBottom() + - getResources().getDimension(R.dimen.bind_app_widget_dialog_checkbox_bottom_padding))); + getResources().getDimension( + R.dimen.bind_app_widget_dialog_checkbox_bottom_padding))); - mAppWidgetManager = AppWidgetManager.getInstance(this); mAlwaysUse.setChecked(mAppWidgetManager.hasBindAppWidgetPermission(mCallingPackage, mProfile.getIdentifier())); setupAlert(); } + + private String getWidgetLabel() { + String label = ""; + for (AppWidgetProviderInfo providerInfo : mAppWidgetManager.getInstalledProviders()) { + if (providerInfo.provider.equals(mComponentName)) { + label = providerInfo.loadLabel(getPackageManager()); + break; + } + } + return label; + } }