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

Commit b8eb4989 authored by Raphael Kim's avatar Raphael Kim Committed by Android Build Coastguard Worker
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 afbe9901
Loading
Loading
Loading
Loading
+29 −4
Original line number 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 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 android.Manifest;
@@ -30,10 +29,13 @@ import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageItemInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.TextUtils;
import android.util.Slog;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
@@ -63,15 +65,38 @@ public class NotificationAccessConfirmationActivity extends Activity

        mComponentName = getIntent().getParcelableExtra(EXTRA_COMPONENT_NAME);
        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);
        p.mTitle = getString(
                R.string.notification_listener_security_warning_title,
                pkgTitle);
                mAppLabel);
        p.mMessage = getString(
                R.string.notification_listener_security_warning_summary,
                pkgTitle);
                mAppLabel);
        p.mPositiveButtonText = getString(R.string.allow);
        p.mPositiveButtonListener = (a, b) -> onAllow();
        p.mNegativeButtonText = getString(R.string.deny);