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

Commit 0b93c3b8 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Send the network logging enabled notification to the current user."...

Merge "Send the network logging enabled notification to the current user." into sc-v2-dev am: b5827095 am: e8ae1c95

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16244061

Change-Id: I7cad7d419389e1254a36a9008d39e70a313e66d0
parents 8df98073 e8ae1c95
Loading
Loading
Loading
Loading
+47 −6
Original line number Diff line number Diff line
@@ -707,6 +707,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    @GuardedBy("getLockObject()")
    private @UserIdInt int mLogoutUserId = UserHandle.USER_NULL;
    /**
     * User the network logging notification was sent to.
     */
    // Guarded by mHandler
    private @UserIdInt int mNetworkLoggingNotificationUserId = UserHandle.USER_NULL;
    private static final boolean ENABLE_LOCK_GUARD = true;
    /**
@@ -9572,7 +9578,15 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
    private @UserIdInt int getCurrentForegroundUserId() {
        try {
            return mInjector.getIActivityManager().getCurrentUser().id;
            UserInfo currentUser = mInjector.getIActivityManager().getCurrentUser();
            if (currentUser == null) {
                // TODO(b/206107460): should not happen on production, but it's happening on unit
                // tests that are not properly setting the expectation (because they don't need it)
                Slogf.wtf(LOG_TAG, "getCurrentForegroundUserId(): mInjector.getIActivityManager()"
                        + ".getCurrentUser() returned null, please ignore when running unit tests");
                return ActivityManager.getCurrentUser();
            }
            return currentUser.id;
        } catch (RemoteException e) {
            Slogf.wtf(LOG_TAG, "cannot get current user");
        }
@@ -9706,10 +9720,18 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                mStateCache.dump(pw);
                pw.println();
            }
            mHandler.post(() -> handleDump(pw));
            dumpResources(pw);
        }
    }
    // Dump state that is guarded by the handler
    private void handleDump(IndentingPrintWriter pw) {
        if (mNetworkLoggingNotificationUserId != UserHandle.USER_NULL) {
            pw.println("mNetworkLoggingNotificationUserId:  " + mNetworkLoggingNotificationUserId);
        }
    }
    private void dumpImmutableState(IndentingPrintWriter pw) {
        pw.println("Immutable state:");
        pw.increaseIndent();
@@ -15194,11 +15216,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
            }
            if (active) {
                if (shouldSendNotification) {
                    mHandler.post(() -> sendNetworkLoggingNotification());
                    mHandler.post(() -> handleSendNetworkLoggingNotification());
                }
            } else {
                mHandler.post(() -> mInjector.getNotificationManager().cancel(
                        SystemMessage.NOTE_NETWORK_LOGGING));
                mHandler.post(() -> handleCancelNetworkLoggingNotification());
            }
        });
    }
@@ -15389,10 +15410,11 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
        return true;
    }
    private void sendNetworkLoggingNotification() {
    private void handleSendNetworkLoggingNotification() {
        final PackageManagerInternal pm = mInjector.getPackageManagerInternal();
        final Intent intent = new Intent(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
        intent.setPackage(pm.getSystemUiServiceComponent().getPackageName());
        mNetworkLoggingNotificationUserId = getCurrentForegroundUserId();
        // Simple notification clicks are immutable
        final PendingIntent pendingIntent = PendingIntent.getBroadcastAsUser(mContext, 0, intent,
                PendingIntent.FLAG_IMMUTABLE, UserHandle.CURRENT);
@@ -15407,7 +15429,26 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
                .setStyle(new Notification.BigTextStyle()
                        .bigText(mContext.getString(R.string.network_logging_notification_text)))
                .build();
        mInjector.getNotificationManager().notify(SystemMessage.NOTE_NETWORK_LOGGING, notification);
        Slogf.i(LOG_TAG, "Sending network logging notification to user %d",
                mNetworkLoggingNotificationUserId);
        mInjector.getNotificationManager().notifyAsUser(/* tag= */ null,
                SystemMessage.NOTE_NETWORK_LOGGING, notification,
                UserHandle.of(mNetworkLoggingNotificationUserId));
    }
    private void handleCancelNetworkLoggingNotification() {
        if (mNetworkLoggingNotificationUserId == UserHandle.USER_NULL) {
            // Happens when setNetworkLoggingActive(false) is called before called with true
            Slogf.d(LOG_TAG, "Not cancelling network logging notification for USER_NULL");
            return;
        }
        Slogf.i(LOG_TAG, "Cancelling network logging notification for user %d",
                mNetworkLoggingNotificationUserId);
        mInjector.getNotificationManager().cancelAsUser(/* tag= */ null,
                SystemMessage.NOTE_NETWORK_LOGGING,
                UserHandle.of(mNetworkLoggingNotificationUserId));
        mNetworkLoggingNotificationUserId = UserHandle.USER_NULL;
    }
    /**