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

Commit f61e6617 authored by Julia Reynolds's avatar Julia Reynolds Committed by Android (Google) Code Review
Browse files

Merge changes Iffe37242,Ib8527138

* changes:
  Use connected boolean as NLS does vs IBinder
  Only log/send broadcasts for changed data
parents 29ee58d7 265d093c
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ public abstract class ConditionProviderService extends Service {

    private Provider mProvider;
    private INotificationManager mNoMan;
    boolean mIsConnected;

    /**
     * The {@link Intent} that must be declared as handled by the service.
@@ -179,7 +180,7 @@ public abstract class ConditionProviderService extends Service {
        try {
            noMan.requestUnbindProvider(mProvider);
            // Disable future messages.
            mProvider = null;
            mIsConnected = false;
        } catch (RemoteException ex) {
            throw ex.rethrowFromSystemServer();
        }
@@ -233,16 +234,16 @@ public abstract class ConditionProviderService extends Service {
     */
    @TestApi
    public boolean isBound() {
        if (mProvider == null) {
        if (!mIsConnected) {
            Log.w(TAG, "Condition provider service not yet bound.");
            return false;
        }
        return true;
        return mIsConnected;
    }

    private final class Provider extends IConditionProvider.Stub {
        @Override
        public void onConnected() {
            mIsConnected = true;
            mHandler.obtainMessage(H.ON_CONNECTED).sendToTarget();
        }

@@ -265,7 +266,7 @@ public abstract class ConditionProviderService extends Service {
        @Override
        public void handleMessage(Message msg) {
            String name = null;
            if (!isBound()) {
            if (!mIsConnected) {
                return;
            }
            try {
+9 −0
Original line number Diff line number Diff line
@@ -2408,6 +2408,15 @@ public class NotificationManagerService extends SystemService {
        public void setNotificationsEnabledForPackage(String pkg, int uid, boolean enabled) {
            enforceSystemOrSystemUI("setNotificationsEnabledForPackage");

            synchronized (mNotificationLock) {
                boolean wasEnabled = mPreferencesHelper.getImportance(pkg, uid)
                        != NotificationManager.IMPORTANCE_NONE;

                if (wasEnabled == enabled) {
                    return;
                }
            }

            mPreferencesHelper.setEnabled(pkg, uid, enabled);
            mMetricsLogger.write(new LogMaker(MetricsEvent.ACTION_BAN_APP_NOTES)
                    .setType(MetricsEvent.TYPE_ACTION)
+10 −2
Original line number Diff line number Diff line
@@ -1508,14 +1508,22 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
    public void testUpdateAppNotifyCreatorBlock() throws Exception {
        mService.setPreferencesHelper(mPreferencesHelper);

        mBinderService.setNotificationsEnabledForPackage(PKG, 0, false);
        mBinderService.setNotificationsEnabledForPackage(PKG, 0, true);
        ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
        verify(mContext, times(1)).sendBroadcastAsUser(captor.capture(), any(), eq(null));

        assertEquals(NotificationManager.ACTION_APP_BLOCK_STATE_CHANGED,
                captor.getValue().getAction());
        assertEquals(PKG, captor.getValue().getPackage());
        assertTrue(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, false));
        assertFalse(captor.getValue().getBooleanExtra(EXTRA_BLOCKED_STATE, true));
    }

    @Test
    public void testUpdateAppNotifyCreatorBlock_notIfMatchesExistingSetting() throws Exception {
        mService.setPreferencesHelper(mPreferencesHelper);

        mBinderService.setNotificationsEnabledForPackage(PKG, 0, false);
        verify(mContext, never()).sendBroadcastAsUser(any(), any(), eq(null));
    }

    @Test