|
20 | 20 | import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
|
21 | 21 |
|
22 | 22 | import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
|
23 |
| -import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_PACKAGE_TITLE; |
24 | 23 | import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID;
|
25 | 24 |
|
26 | 25 | import android.Manifest;
|
|
30 | 29 | import android.content.ComponentName;
|
31 | 30 | import android.content.Context;
|
32 | 31 | import android.content.DialogInterface;
|
| 32 | +import android.content.pm.ApplicationInfo; |
| 33 | +import android.content.pm.PackageItemInfo; |
33 | 34 | import android.content.pm.PackageManager;
|
34 | 35 | import android.content.pm.ServiceInfo;
|
35 | 36 | import android.os.Bundle;
|
36 | 37 | import android.os.UserHandle;
|
| 38 | +import android.text.TextUtils; |
37 | 39 | import android.util.Slog;
|
38 | 40 | import android.view.WindowManager;
|
39 | 41 | import android.view.accessibility.AccessibilityEvent;
|
@@ -63,15 +65,38 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
63 | 65 |
|
64 | 66 | mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
|
65 | 67 | 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 | + } |
67 | 92 |
|
68 | 93 | AlertController.AlertParams p = new AlertController.AlertParams(this);
|
69 | 94 | p.mTitle = getString(
|
70 | 95 | R.string.notification_listener_security_warning_title,
|
71 |
| - pkgTitle); |
| 96 | + mAppLabel); |
72 | 97 | p.mMessage = getString(
|
73 | 98 | R.string.notification_listener_security_warning_summary,
|
74 |
| - pkgTitle); |
| 99 | + mAppLabel); |
75 | 100 | p.mPositiveButtonText = getString(R.string.allow);
|
76 | 101 | p.mPositiveButtonListener = (a, b) -> onAllow();
|
77 | 102 | p.mNegativeButtonText = getString(R.string.deny);
|
|
0 commit comments