Skip to content

Commit 5fb0705

Browse files
author
Valentin Iftime
committed
[DO NO MERGE] Enforce INTERACT_ACROSS_USERS_FULL permission for NotificationAccessDetails
When using EXTRA_USER_HANDLE, check for INTERACT_ACROSS_USERS_FULL permission on calling package. Bug: 259385017 Test: 1. Build a test app that creates and starts an intent to NOTIFICATION_LISTENER_DETAIL_SETTINGS while setting the intent extra android.intent.extra.user_handle to UserHandle(secondaryUserId). 2. Create and switch to a secondary user Settings > System > Multiple users > Allow multiple users > Add user > Switch to New user 3. Open Settings > Notifications > Device & app notifications and choose an app from the list (uses android.permission.BIND_NOTIFICATION_LISTENER_SERVICE). Enable Device & app notifications for selected app and disable all attributed permissions. 4. Switch back to the Owner user. 5. Get the userId of the secondary user: adb shell pm list users. 6. Open the test app and enter the userId for the secondary user and the component name that uses android.permission.BIND_NOTIFICATION_LISTENER_SERVICE. 8. In the settings window that open, enable all 4 sub-options. 9. Switch to the secondary user and note that the all sub-options for the app are disabled. Change-Id: I875b9f2fc32c252acdcf8374a14067836e0f1ac6 Merged-In: I875b9f2fc32c252acdcf8374a14067836e0f1ac6
1 parent 86914be commit 5fb0705

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/com/android/settings/applications/specialaccess/notificationaccess/NotificationAccessDetails.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.android.settings.applications.specialaccess.notificationaccess;
1818

19+
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
20+
21+
import android.Manifest;
1922
import android.app.Activity;
2023
import android.app.NotificationManager;
2124
import android.app.settings.SettingsEnums;
@@ -30,6 +33,7 @@
3033
import android.os.UserManager;
3134
import android.provider.Settings;
3235
import android.service.notification.NotificationListenerService;
36+
import android.text.TextUtils;
3337
import android.util.IconDrawableFactory;
3438
import android.util.Log;
3539
import android.util.Slog;
@@ -42,6 +46,7 @@
4246
import com.android.settings.R;
4347
import com.android.settings.applications.AppInfoBase;
4448
import com.android.settings.overlay.FeatureFactory;
49+
import com.android.settings.password.PasswordUtils;
4550
import com.android.settings.widget.EntityHeaderController;
4651
import com.android.settingslib.applications.AppUtils;
4752

@@ -139,6 +144,41 @@ protected AlertDialog createDialog(int id, int errorCode) {
139144
return null;
140145
}
141146

147+
@Override
148+
protected String retrieveAppEntry() {
149+
final Bundle args = getArguments();
150+
final Intent intent = (args == null) ?
151+
getIntent() : (Intent) args.getParcelable("intent");
152+
153+
if (intent != null && intent.hasExtra(Intent.EXTRA_USER_HANDLE)) {
154+
if (!hasInteractAcrossUsersPermission()) {
155+
finish();
156+
}
157+
}
158+
159+
return super.retrieveAppEntry();
160+
}
161+
162+
private boolean hasInteractAcrossUsersPermission() {
163+
final String callingPackageName = PasswordUtils.getCallingAppPackageName(
164+
getActivity().getActivityToken());
165+
166+
if (TextUtils.isEmpty(callingPackageName)) {
167+
Log.w(TAG, "Not able to get calling package name for permission check");
168+
return false;
169+
}
170+
171+
if (getContext().getPackageManager().checkPermission(
172+
Manifest.permission.INTERACT_ACROSS_USERS_FULL, callingPackageName)
173+
!= PERMISSION_GRANTED) {
174+
Log.w(TAG, "Package " + callingPackageName + " does not have required permission "
175+
+ Manifest.permission.INTERACT_ACROSS_USERS_FULL);
176+
return false;
177+
}
178+
179+
return true;
180+
}
181+
142182
public void updatePreference(SwitchPreference preference) {
143183
final CharSequence label = mPackageInfo.applicationInfo.loadLabel(mPm);
144184
preference.setChecked(isServiceEnabled(mComponentName));

0 commit comments

Comments
 (0)