Skip to content

Commit 8d749c5

Browse files
author
Raphael Kim
committed
Extract app label from component name in notification access confirmation UI
Bug: 228178437 Test: Manually tested on POC Change-Id: I8613d9b87a53d4641c0689bca9c961c66a2e9415 Merged-In: I8613d9b87a53d4641c0689bca9c961c66a2e9415
1 parent 06139d3 commit 8d749c5

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

src/com/android/settings/notification/NotificationAccessConfirmationActivity.java

+29-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
2121

2222
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
23-
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_PACKAGE_TITLE;
2423
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID;
2524

2625
import android.Manifest;
@@ -30,10 +29,13 @@
3029
import android.content.ComponentName;
3130
import android.content.Context;
3231
import android.content.DialogInterface;
32+
import android.content.pm.ApplicationInfo;
33+
import android.content.pm.PackageItemInfo;
3334
import android.content.pm.PackageManager;
3435
import android.content.pm.ServiceInfo;
3536
import android.os.Bundle;
3637
import android.os.UserHandle;
38+
import android.text.TextUtils;
3739
import android.util.Slog;
3840
import android.view.WindowManager;
3941
import android.view.accessibility.AccessibilityEvent;
@@ -63,15 +65,38 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
6365

6466
mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
6567
mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
66-
String pkgTitle = getIntent().getStringExtra(EXTRA_PACKAGE_TITLE);
68+
CharSequence mAppLabel;
69+
70+
if (mComponentName == null || mComponentName.getPackageName() == null) {
71+
finish();
72+
return;
73+
}
74+
75+
try {
76+
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
77+
mComponentName.getPackageName(), 0);
78+
mAppLabel = applicationInfo.loadSafeLabel(getPackageManager(),
79+
PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
80+
PackageItemInfo.SAFE_LABEL_FLAG_TRIM
81+
| PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
82+
} catch (PackageManager.NameNotFoundException e) {
83+
Slog.e(LOG_TAG, "Couldn't find app with package name for " + mComponentName, e);
84+
finish();
85+
return;
86+
}
87+
88+
if (TextUtils.isEmpty(mAppLabel)) {
89+
finish();
90+
return;
91+
}
6792

6893
AlertController.AlertParams p = new AlertController.AlertParams(this);
6994
p.mTitle = getString(
7095
R.string.notification_listener_security_warning_title,
71-
pkgTitle);
96+
mAppLabel);
7297
p.mMessage = getString(
7398
R.string.notification_listener_security_warning_summary,
74-
pkgTitle);
99+
mAppLabel);
75100
p.mPositiveButtonText = getString(R.string.allow);
76101
p.mPositiveButtonListener = (a, b) -> onAllow();
77102
p.mNegativeButtonText = getString(R.string.deny);

0 commit comments

Comments
 (0)