[CDM][NLS] Check if the NLS service has an intent-filter am: 59cdc3e20c
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/29711247
Change-Id: I26b92140443f28084cb514da60e1febcf599dfc8
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
index a6b565a..f01e23a 100644
--- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -29,12 +29,14 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
-import android.content.pm.ServiceInfo;
+import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
+import android.service.notification.NotificationListenerService;
import android.text.TextUtils;
import android.util.Slog;
import android.view.WindowManager;
@@ -44,6 +46,8 @@
import com.android.internal.app.AlertController;
import com.android.settings.R;
+import java.util.List;
+
/** @hide */
public class NotificationAccessConfirmationActivity extends Activity
implements DialogInterface {
@@ -92,6 +96,31 @@
return;
}
+ // Check NLS service info.
+ String requiredPermission = Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
+ Intent NLSIntent = new Intent(NotificationListenerService.SERVICE_INTERFACE);
+ List<ResolveInfo> matchedServiceList = getPackageManager().queryIntentServicesAsUser(
+ NLSIntent, /* flags */ 0, mUserId);
+ boolean hasNLSIntentFilter = false;
+ for (ResolveInfo service : matchedServiceList) {
+ if (service.serviceInfo.packageName.equals(mComponentName.getPackageName())) {
+ if (!requiredPermission.equals(service.serviceInfo.permission)) {
+ Slog.e(LOG_TAG, "Service " + mComponentName + " lacks permission "
+ + requiredPermission);
+ finish();
+ return;
+ }
+ hasNLSIntentFilter = true;
+ break;
+ }
+ }
+ if (!hasNLSIntentFilter) {
+ Slog.e(LOG_TAG, "Service " + mComponentName + " lacks an intent-filter action "
+ + "for android.service.notification.NotificationListenerService.");
+ finish();
+ return;
+ }
+
AlertController.AlertParams p = new AlertController.AlertParams(this);
p.mTitle = getString(
R.string.notification_listener_security_warning_title,
@@ -126,19 +155,6 @@
}
private void onAllow() {
- String requiredPermission = Manifest.permission.BIND_NOTIFICATION_LISTENER_SERVICE;
- try {
- ServiceInfo serviceInfo = getPackageManager().getServiceInfo(mComponentName, 0);
- if (!requiredPermission.equals(serviceInfo.permission)) {
- Slog.e(LOG_TAG,
- "Service " + mComponentName + " lacks permission " + requiredPermission);
- return;
- }
- } catch (PackageManager.NameNotFoundException e) {
- Slog.e(LOG_TAG, "Failed to get service info for " + mComponentName, e);
- return;
- }
-
mNm.setNotificationListenerAccessGranted(mComponentName, true);
finish();
@@ -150,12 +166,6 @@
}
@Override
- public void onBackPressed() {
- // Suppress finishing the activity on back button press,
- // consistently with the permission dialog behavior
- }
-
- @Override
public void cancel() {
finish();
}