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

Commit fad82fdc authored by Lorenzo Colitti's avatar Lorenzo Colitti
Browse files

Check registering system default callback needs NETWORK_SETTINGS.

Also address a code review comment.

Bug: 173331190
Test: test-only change
Change-Id: Ia68f482af6d10af203bdbd4e14a12ae0b12bb6b5
parent 3dc6dbe8
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -5275,7 +5275,8 @@ public class ConnectivityService extends IConnectivityManager.Stub
        // changes don't alter request matching.
        if (reqType == NetworkRequest.Type.TRACK_SYSTEM_DEFAULT &&
                (!networkCapabilities.equalRequestableCapabilities(defaultNc))) {
            Log.wtf(TAG, "TRACK_SYSTEM_DEFAULT capabilities don't match default request: "
            throw new IllegalStateException(
                    "TRACK_SYSTEM_DEFAULT capabilities don't match default request: "
                    + networkCapabilities + " vs. " + defaultNc);
        }

+18 −0
Original line number Diff line number Diff line
@@ -3837,6 +3837,24 @@ public class ConnectivityServiceTest {
        mCm.unregisterNetworkCallback(cellNetworkCallback);
    }

    @Test
    public void testRegisterSystemDefaultCallbackRequiresNetworkSettings() throws Exception {
        mCellNetworkAgent = new TestNetworkAgentWrapper(TRANSPORT_CELLULAR);
        mCellNetworkAgent.connect(false /* validated */);

        final Handler handler = new Handler(ConnectivityThread.getInstanceLooper());
        final TestNetworkCallback callback = new TestNetworkCallback();
        assertThrows(SecurityException.class,
                () -> mCm.registerSystemDefaultNetworkCallback(callback, handler));
        callback.assertNoCallback();

        mServiceContext.setPermission(Manifest.permission.NETWORK_SETTINGS,
                PERMISSION_GRANTED);
        mCm.registerSystemDefaultNetworkCallback(callback, handler);
        callback.expectAvailableCallbacksUnvalidated(mCellNetworkAgent);
        mCm.unregisterNetworkCallback(callback);
    }

    private void setCaptivePortalMode(int mode) {
        ContentResolver cr = mServiceContext.getContentResolver();
        Settings.Global.putInt(cr, Settings.Global.CAPTIVE_PORTAL_MODE, mode);