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

Commit 152893d0 authored by Jack Yu's avatar Jack Yu Committed by android-build-merger
Browse files

Merge "Fixed that MMS is not always allowed" into qt-dev

am: 0e3e1178

Change-Id: Ib7047173dec1f26fd5c8bc634fc6dce342e5a93a
parents e9966ec4 0e3e1178
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -3636,6 +3636,8 @@ public class SubscriptionController extends ISub.Stub {
        }
    }

    // TODO: This method should belong to Telephony manager like other data enabled settings and
    // override APIs. Remove this once TelephonyManager API is added.
    @Override
    public boolean setAlwaysAllowMmsData(int subId, boolean alwaysAllow) {
        if (DBG) logd("[setAlwaysAllowMmsData]+ alwaysAllow:" + alwaysAllow + " subId:" + subId);
@@ -3646,11 +3648,9 @@ public class SubscriptionController extends ISub.Stub {
        final long identity = Binder.clearCallingIdentity();
        try {
            validateSubId(subId);
            DataEnabledOverride dataEnabledOverride =
                    new DataEnabledOverride(getDataEnabledOverrideRules(subId));
            dataEnabledOverride.setAlwaysAllowMms(alwaysAllow);

            return setDataEnabledOverrideRules(subId, dataEnabledOverride.getRules());
            Phone phone = PhoneFactory.getPhone(getPhoneId(subId));
            if (phone == null) return false;
            return phone.getDataEnabledSettings().setAlwaysAllowMmsData(alwaysAllow);
        } finally {
            Binder.restoreCallingIdentity(identity);
        }
+21 −1
Original line number Diff line number Diff line
@@ -197,6 +197,26 @@ public class DataEnabledSettings {
                Settings.Global.MOBILE_DATA, mPhone.getSubId(), defaultVal);
    }

    /**
     * Set whether always allowing MMS data connection.
     *
     * @param alwaysAllow {@code true} if MMS data is always allowed.
     *
     * @return {@code false} if the setting is changed.
     */
    public synchronized boolean setAlwaysAllowMmsData(boolean alwaysAllow) {
        localLog("setAlwaysAllowMmsData", alwaysAllow);
        mDataEnabledOverride.setAlwaysAllowMms(alwaysAllow);
        boolean changed = SubscriptionController.getInstance()
                .setDataEnabledOverrideRules(mPhone.getSubId(), mDataEnabledOverride.getRules());
        if (changed) {
            updateDataEnabled();
            notifyDataEnabledOverrideChanged();
        }

        return changed;
    }

    /**
     * Set allowing mobile data during voice call.
     *
@@ -206,7 +226,7 @@ public class DataEnabledSettings {
     * @return {@code false} if the setting is changed.
     */
    public synchronized boolean setAllowDataDuringVoiceCall(boolean allow) {
        localLog("setDataEnabledOverrideRules", allow);
        localLog("setAllowDataDuringVoiceCall", allow);
        mDataEnabledOverride.setDataAllowedInVoiceCall(allow);
        boolean changed = SubscriptionController.getInstance()
                .setDataEnabledOverrideRules(mPhone.getSubId(), mDataEnabledOverride.getRules());
+13 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.times;
@@ -989,4 +990,16 @@ public class SubscriptionControllerTest extends TelephonyTest {
        return new UiccSlotInfo(active, false, "fake card Id",
                UiccSlotInfo.CARD_STATE_INFO_PRESENT, logicalSlotIndex, true, true);
    }

    // TODO: Move this test once SubscriptionManager.setAlwaysAllowMmsData is moved to telephony
    // manager.
    @Test
    @SmallTest
    public void testSetAlwaysAllowMmsData() throws Exception {
        mSubscriptionControllerUT.setAlwaysAllowMmsData(0, true);
        verify(mDataEnabledSettings).setAlwaysAllowMmsData(eq(true));
        clearInvocations(mDataEnabledSettings);
        mSubscriptionControllerUT.setAlwaysAllowMmsData(0, false);
        verify(mDataEnabledSettings).setAlwaysAllowMmsData(eq(false));
    }
}
+126 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony.dataconnection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;

import android.os.HandlerThread;
import android.telephony.data.ApnSetting;
import android.test.suitebuilder.annotation.SmallTest;

import com.android.internal.telephony.TelephonyTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;

import java.util.Objects;

public class DataEnabledSettingsTest extends TelephonyTest {

    private DataEnabledSettings mDataEnabledSettingsUT;

    private DataEnabledSettingsTestHandler mDataEnabledSettingsTestHandler;

    private String mRules = "";

    private class DataEnabledSettingsTestHandler extends HandlerThread {

        private DataEnabledSettingsTestHandler(String name) {
            super(name);
        }

        @Override
        public void onLooperPrepared() {
            mDataEnabledSettingsUT = new DataEnabledSettings(mPhone);
            setReady(true);
        }
    }

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());

        doReturn(mRules).when(mSubscriptionController).getDataEnabledOverrideRules(anyInt());

        doAnswer(invocation -> {
            String rules = (String) invocation.getArguments()[1];
            boolean changed = !Objects.equals(mRules, rules);
            mRules = rules;
            return changed;
        }).when(mSubscriptionController).setDataEnabledOverrideRules(anyInt(), anyString());

        mDataEnabledSettingsTestHandler = new DataEnabledSettingsTestHandler(
                getClass().getSimpleName());
        mDataEnabledSettingsTestHandler.start();
        waitUntilReady();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test
    @SmallTest
    public void testSetDataAllowedInVoiceCall() throws Exception {
        mDataEnabledSettingsUT.setAllowDataDuringVoiceCall(true);
        ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSubscriptionController).setDataEnabledOverrideRules(anyInt(),
                stringCaptor.capture());
        assertEquals("*=nonDefault&inVoiceCall", stringCaptor.getValue());

        clearInvocations(mSubscriptionController);

        mDataEnabledSettingsUT.setAllowDataDuringVoiceCall(false);
        verify(mSubscriptionController).setDataEnabledOverrideRules(anyInt(),
                stringCaptor.capture());
        assertEquals("", stringCaptor.getValue());
    }

    @Test
    @SmallTest
    public void testSetAlwaysAllowMmsData() throws Exception {
        mDataEnabledSettingsUT.setUserDataEnabled(false);
        assertTrue(mDataEnabledSettingsUT.setAlwaysAllowMmsData(true));
        ArgumentCaptor<String> stringCaptor = ArgumentCaptor.forClass(String.class);
        verify(mSubscriptionController).setDataEnabledOverrideRules(anyInt(),
                stringCaptor.capture());
        assertEquals("mms=unconditionally", stringCaptor.getValue());
        assertTrue(mDataEnabledSettingsUT.isDataEnabled(ApnSetting.TYPE_MMS));

        clearInvocations(mSubscriptionController);

        assertTrue(mDataEnabledSettingsUT.setAlwaysAllowMmsData(false));
        verify(mSubscriptionController).setDataEnabledOverrideRules(anyInt(),
                stringCaptor.capture());
        assertEquals("", stringCaptor.getValue());
        assertFalse(mDataEnabledSettingsUT.isDataEnabled(ApnSetting.TYPE_MMS));

        mDataEnabledSettingsUT.setUserDataEnabled(true);
        assertTrue(mDataEnabledSettingsUT.isDataEnabled(ApnSetting.TYPE_MMS));
    }
}