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

Commit 558fd78b authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Resolve NotificationManager hidden APIs

Resolve the Telecom dependency on the NotificationManager#notifyAsUser
and NotificationManager#cancelAsUser hidden APIs. Instead, we can create
a user context via Context#createContextAsUser and use the public APIs
(notify and cancel) instead.

Bug: 305310218
Flag: com.android.server.telecom.flags.resolve_hidden_dependencies_two
Test: atest TelecomUnitTests
Change-Id: Icaba207deaf8fb2dc526bf658be8e3804624f40a
parent cec70ca3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -652,7 +652,8 @@ public class CallsManager extends Call.ListenerBase
        mPhoneAccountRegistrar = phoneAccountRegistrar;
        mPhoneAccountRegistrar.addListener(mPhoneAccountListener);
        mMissedCallNotifier = missedCallNotifier;
        mDisconnectedCallNotifier = disconnectedCallNotifierFactory.create(mContext, this);
        mDisconnectedCallNotifier = disconnectedCallNotifierFactory.create(mContext, this,
                featureFlags);
        StatusBarNotifier statusBarNotifier = new StatusBarNotifier(context, this);
        mWiredHeadsetManager = wiredHeadsetManager;
        mSystemStateHelper = systemStateHelper;
+2 −6
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import android.annotation.Nullable;
import android.app.AppOpsManager;
import android.app.KeyguardManager;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.AttributionSource;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
@@ -302,7 +301,6 @@ public class InCallController extends CallsManagerListenerBase implements
        private boolean mIsConnected = false;
        private boolean mIsBound = false;
        private boolean mIsNullBinding = false;
        private NotificationManager mNotificationManager;

        //this is really used for cases where the userhandle for a call
        //does not match what we want to use for bindAsUser
@@ -3322,8 +3320,6 @@ public class InCallController extends CallsManagerListenerBase implements
        } catch (PackageManager.NameNotFoundException e) {
            appName = packageName;
        }
        NotificationManager notificationManager = (NotificationManager) mContext
                .getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder = new Notification.Builder(mContext,
                NotificationChannelManager.CHANNEL_ID_IN_CALL_SERVICE_CRASH);
        builder.setSmallIcon(R.drawable.ic_phone)
@@ -3334,8 +3330,8 @@ public class InCallController extends CallsManagerListenerBase implements
                .setStyle(new Notification.BigTextStyle()
                        .bigText(mContext.getText(
                                R.string.notification_incallservice_not_responding_body)));
        notificationManager.notifyAsUser(NOTIFICATION_TAG, IN_CALL_SERVICE_NOTIFICATION_ID,
                builder.build(), userHandle);
        UserUtil.processNotification(mContext, userHandle, NOTIFICATION_TAG,
                IN_CALL_SERVICE_NOTIFICATION_ID, builder.build(), mFeatureFlags);
    }

    private void updateCallTracking(Call call, InCallServiceInfo info, boolean isAdd) {
+3 −2
Original line number Diff line number Diff line
@@ -347,7 +347,7 @@ public class TelecomSystem {
                    );

            AudioProcessingNotification audioProcessingNotification =
                    new AudioProcessingNotification(mContext);
                    new AudioProcessingNotification(mContext, mFeatureFlags);

            ToastFactory toastFactory = new ToastFactory() {
                @Override
@@ -391,7 +391,8 @@ public class TelecomSystem {
            CallStreamingNotification callStreamingNotification =
                    new CallStreamingNotification(mContext,
                            (packageName, userHandle) -> AppLabelProxy.Util.getAppLabel(mContext,
                                    userHandle, packageName, mFeatureFlags), asyncTaskExecutor);
                                    userHandle, packageName, mFeatureFlags), asyncTaskExecutor,
                            mFeatureFlags);

            mCallsManager = new CallsManager(
                    mContext,
+26 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.telecom;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
@@ -167,4 +169,28 @@ public final class UserUtil {
        // return the current user.
        return currentUser;
    }

    public static void processNotification(Context context, UserHandle userHandle, String tag,
            int id, Notification notification, FeatureFlags featureFlags) {
        if (featureFlags.resolveHiddenDependenciesTwo()) {
            Context userContext = context.createContextAsUser(userHandle, 0);
            NotificationManager userNotificationMgr = userContext.getSystemService(
                    NotificationManager.class);
            if (userNotificationMgr != null) {
                if (notification != null) {
                    userNotificationMgr.notify(tag, id, notification);
                } else {
                    userNotificationMgr.cancel(tag, id);
                }
            }
        } else {
            NotificationManager notificationMgr = (NotificationManager) context.getSystemService(
                    Context.NOTIFICATION_SERVICE);
            if (notification != null) {
                notificationMgr.notifyAsUser(tag, id, notification, userHandle);
            } else {
                notificationMgr.cancelAsUser(tag, id, userHandle);
            }
        }
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -190,7 +190,7 @@ public class TelecomService extends Service implements TelecomSystem.Component {
                            new Timeouts.Adapter(),
                            new AsyncRingtonePlayer(),
                            new PhoneNumberUtilsAdapterImpl(),
                            new IncomingCallNotifier(context),
                            new IncomingCallNotifier(context, featureFlags),
                            ToneGenerator::new,
                            new CallAudioRouteStateMachine.Factory(),
                            new CallAudioModeStateMachine.Factory(),
@@ -242,7 +242,7 @@ public class TelecomService extends Service implements TelecomSystem.Component {
                                public void updateEmergencyCallNotification(Context context,
                                        boolean showNotification) {
                                    BlockedNumbersUtil.updateEmergencyCallNotification(context,
                                            showNotification);
                                            showNotification, featureFlags);
                                }
                            },
                            featureFlags,
Loading