Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 3528c87f authored by Raphael Kim's avatar Raphael Kim Committed by Kevin F. Haggerty
Browse files

Extract app label from component name in notification access confirmation UI

Bug: 228178437
Test: Manually tested on POC
Change-Id: I8613d9b87a53d4641c0689bca9c961c66a2e9415
Merged-In: I8613d9b87a53d4641c0689bca9c961c66a2e9415
(cherry picked from commit 8d749c55)
Merged-In: I8613d9b87a53d4641c0689bca9c961c66a2e9415
parent 81bde12a
Loading
Loading
Loading
Loading
+29 −4
Original line number Original line Diff line number Diff line
@@ -20,7 +20,6 @@ package com.android.settings.notification;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;


import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_PACKAGE_TITLE;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID;
import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_USER_ID;


import android.Manifest;
import android.Manifest;
@@ -30,10 +29,13 @@ import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.ComponentName;
import android.content.Context;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.Bundle;
import android.os.UserHandle;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Slog;
import android.util.Slog;
import android.view.WindowManager;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityEvent;
@@ -63,15 +65,38 @@ public class NotificationAccessConfirmationActivity extends Activity


        mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
        mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
        mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
        String pkgTitle = getIntent().getStringExtra(EXTRA_PACKAGE_TITLE);
        CharSequence mAppLabel;

        if (mComponentName == null || mComponentName.getPackageName() == null) {
            finish();
            return;
        }

        try {
            ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(
                    mComponentName.getPackageName(), 0);
            mAppLabel = applicationInfo.loadSafeLabel(getPackageManager(),
                    PackageItemInfo.DEFAULT_MAX_LABEL_SIZE_PX,
                    PackageItemInfo.SAFE_LABEL_FLAG_TRIM
                            | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE);
        } catch (PackageManager.NameNotFoundException e) {
            Slog.e(LOG_TAG, "Couldn't find app with package name for " + mComponentName, e);
            finish();
            return;
        }

        if (TextUtils.isEmpty(mAppLabel)) {
            finish();
            return;
        }


        AlertController.AlertParams p = new AlertController.AlertParams(this);
        AlertController.AlertParams p = new AlertController.AlertParams(this);
        p.mTitle = getString(
        p.mTitle = getString(
                R.string.notification_listener_security_warning_title,
                R.string.notification_listener_security_warning_title,
                pkgTitle);
                mAppLabel);
        p.mMessage = getString(
        p.mMessage = getString(
                R.string.notification_listener_security_warning_summary,
                R.string.notification_listener_security_warning_summary,
                pkgTitle);
                mAppLabel);
        p.mPositiveButtonText = getString(R.string.allow);
        p.mPositiveButtonText = getString(R.string.allow);
        p.mPositiveButtonListener = (a, b) -> onAllow();
        p.mPositiveButtonListener = (a, b) -> onAllow();
        p.mNegativeButtonText = getString(R.string.deny);
        p.mNegativeButtonText = getString(R.string.deny);