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

Commit 1e451cf7 authored by Arc Wang's avatar Arc Wang
Browse files

[Wi-Fi] Prevent fatal exception for null intent action

Intent action may be null.

Bug: 139020487
Test: WifiScanModeActivityTest
      WifiNoInternetDialogTest
      WifiDppConfiguratorActivityTest
      WifiDppEnrolleeActivityTest
Change-Id: Ie6119a86aaee1a6b40710705a0ea7d92c24736d6
parent 6ef36e9c
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -55,9 +55,9 @@ public final class WifiNoInternetDialog extends AlertActivity implements
    private boolean mButtonClicked;
    private boolean mButtonClicked;


    private boolean isKnownAction(Intent intent) {
    private boolean isKnownAction(Intent intent) {
        return intent.getAction().equals(ACTION_PROMPT_UNVALIDATED)
        return ACTION_PROMPT_UNVALIDATED.equals(intent.getAction())
                || intent.getAction().equals(ACTION_PROMPT_LOST_VALIDATION)
                || ACTION_PROMPT_LOST_VALIDATION.equals(intent.getAction())
                || intent.getAction().equals(ACTION_PROMPT_PARTIAL_CONNECTIVITY);
                || ACTION_PROMPT_PARTIAL_CONNECTIVITY.equals(intent.getAction());
    }
    }


    @Override
    @Override
+2 −2
Original line number Original line Diff line number Diff line
@@ -46,8 +46,8 @@ public class WifiScanModeActivity extends FragmentActivity {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        Intent intent = getIntent();
        Intent intent = getIntent();
        if (savedInstanceState == null) {
        if (savedInstanceState == null) {
            if (intent != null && intent.getAction()
            if (intent != null && WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE
                    .equals(WifiManager.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE)) {
                    .equals(intent.getAction())) {
                ApplicationInfo ai;
                ApplicationInfo ai;
                mApp = getCallingPackage();
                mApp = getCallingPackage();
                try {
                try {
+7 −1
Original line number Original line Diff line number Diff line
@@ -109,9 +109,15 @@ public class WifiDppConfiguratorActivity extends WifiDppBaseActivity implements


    @Override
    @Override
    protected void handleIntent(Intent intent) {
    protected void handleIntent(Intent intent) {
        String action = intent != null ? intent.getAction() : null;
        if (action == null) {
            finish();
            return;
        }

        boolean cancelActivity = false;
        boolean cancelActivity = false;
        WifiNetworkConfig config;
        WifiNetworkConfig config;
        switch (intent.getAction()) {
        switch (action) {
            case ACTION_CONFIGURATOR_QR_CODE_SCANNER:
            case ACTION_CONFIGURATOR_QR_CODE_SCANNER:
                config = WifiNetworkConfig.getValidConfigOrNull(intent);
                config = WifiNetworkConfig.getValidConfigOrNull(intent);
                if (config == null) {
                if (config == null) {
+7 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,13 @@ public class WifiDppEnrolleeActivity extends WifiDppBaseActivity implements


    @Override
    @Override
    protected void handleIntent(Intent intent) {
    protected void handleIntent(Intent intent) {
        switch (intent.getAction()) {
        String action = intent != null ? intent.getAction() : null;
        if (action == null) {
            finish();
            return;
        }

        switch (action) {
            case ACTION_ENROLLEE_QR_CODE_SCANNER:
            case ACTION_ENROLLEE_QR_CODE_SCANNER:
                String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
                String ssid = intent.getStringExtra(WifiDppUtils.EXTRA_WIFI_SSID);
                showQrCodeScannerFragment(ssid);
                showQrCodeScannerFragment(ssid);
+31 −0
Original line number Original line 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.settings.wifi;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;

@RunWith(RobolectricTestRunner.class)
public class WifiNoInternetDialogTest {
    @Test
    public void launchActivity_noIntentAction_shouldNotFatalException() {
        WifiNoInternetDialog wifiNoInternetDialog =
                Robolectric.setupActivity(WifiNoInternetDialog.class);
    }
}
Loading