[CDM][NLS] Check if the NLS service has an intent-filter
Bug: 363248394
Test: CTS
Flag: EXEMPT bugfix
Change-Id: Ib79c219cde8d73a218ceb7911f4552d43e384d8e
Merged-In: Ib79c219cde8d73a218ceb7911f4552d43e384d8e
(cherry picked from commit 7ae59a42eb
)
This commit is contained in:
@@ -29,12 +29,14 @@ import android.app.NotificationManager;
|
||||
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.AlertActivity;
|
||||
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 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
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 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
}
|
||||
|
||||
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();
|
||||
@@ -149,12 +165,6 @@ public class NotificationAccessConfirmationActivity extends Activity
|
||||
return AlertActivity.dispatchPopulateAccessibilityEvent(this, event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// Suppress finishing the activity on back button press,
|
||||
// consistently with the permission dialog behavior
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
finish();
|
||||
|
Reference in New Issue
Block a user