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

Commit f6c0004d authored by Eric Schwarzenbach's avatar Eric Schwarzenbach
Browse files

Change header of wifi detail page to "Network info".

Creates a lifecycle observer to modify the action bar.

Bug: 37252029
Test: make -j40 RunSettingsRoboTests
Change-Id: Iff48ed51f533c3b7b2a099f83c3216ae975f061f
parent cbedc3f0
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1971,6 +1971,8 @@
    <string name="wifi_advanced_ip_address_title">IP address</string>
    <!-- Wifi Network Details -->
    <!-- Wifi details title-->
    <string name="wifi_details_title">Network info</string>
    <!-- Wifi details preference title to display router IP subnet mask -->
    <string name="wifi_details_subnet_mask">Subnet mask</string>
    <!-- Wifi details preference title to display router DNS info -->
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.details;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnCreate;

/**
 * ActionBar lifecycle observer for {@link WifiNetworkDetailsFragment}.
 */
public class WifiDetailActionBarObserver implements LifecycleObserver, OnCreate {

    private final Fragment mFragment;
    private final Context mContext;

    public WifiDetailActionBarObserver(Context context, Fragment fragment) {
        mContext = context;
        mFragment = fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (mFragment.getActivity() != null) {
            mFragment.getActivity().getActionBar()
                    .setTitle(mContext.getString(R.string.wifi_details_title));
        }
    }
}
+7 −5
Original line number Diff line number Diff line
@@ -21,15 +21,14 @@ import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;

import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.vpn2.ConnectivityManagerWrapperImpl;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.wifi.AccessPoint;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
@@ -39,13 +38,18 @@ import java.util.List;
 * {@link AccessPoint#saveWifiState(Bundle)} in order to properly render this page.
 */
public class WifiNetworkDetailsFragment extends DashboardFragment {

    private static final String TAG = "WifiNetworkDetailsFrg";

    private AccessPoint mAccessPoint;
    private WifiDetailPreferenceController mWifiDetailPreferenceController;
    private WifiDetailActionBarObserver mWifiDetailActionBarObserver;

    @Override
    public void onAttach(Context context) {
        mWifiDetailActionBarObserver = new WifiDetailActionBarObserver(context, this);
        getLifecycle().addObserver(mWifiDetailActionBarObserver);

        mAccessPoint = new AccessPoint(context, getArguments());
        super.onAttach(context);
    }
@@ -78,8 +82,6 @@ public class WifiNetworkDetailsFragment extends DashboardFragment {
                context.getSystemService(WifiManager.class),
                mMetricsFeatureProvider);

        ArrayList<AbstractPreferenceController> controllers = new ArrayList(1);
        controllers.add(mWifiDetailPreferenceController);
        return controllers;
        return new ArrayList<>(Collections.singletonList(mWifiDetailPreferenceController));
    }
}
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.details;

import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.ActionBar;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.core.lifecycle.Lifecycle;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class WifiDetailActionBarObserverTest {

    @Mock private Bundle mockBundle;
    @Mock private Activity mockActivity;
    @Mock private ActionBar mockActionBar;
    @Mock private WifiNetworkDetailsFragment mockFragment;

    private Context mContext = RuntimeEnvironment.application;
    private Lifecycle mLifecycle;
    private WifiDetailActionBarObserver mObserver;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);

        mLifecycle = new Lifecycle();

        when(mockFragment.getActivity()).thenReturn(mockActivity);
        when(mockActivity.getActionBar()).thenReturn(mockActionBar);

        mObserver = new WifiDetailActionBarObserver(mContext, mockFragment);
        mLifecycle.addObserver(mObserver);
    }

    @Test
    public void actionBarIsSetToNetworkInfo() {
        mLifecycle.onCreate(mockBundle);

        verify(mockActionBar).setTitle(mContext.getString(R.string.wifi_details_title));
    }
}