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

Commit 7a62ab1f authored by Weng Su's avatar Weng Su
Browse files

[Provider Model] Internet Panel - Airplane mode is on

- Add "Airplane mode is on" to sub-title
  - Set the header layout to CENTER_HORIZONTAL if it's no icon

- Hide "Settings" button

- Screenshot
  https://screenshot.googleplex.com/6m5dFVZu7ar4nKW

Bug: 178717651
Test: manual test
atest InternetConnectivityPanelTest \
      PanelFragmentTest \
      ProviderModelSliceTest

Change-Id: I899a817fd99415e9cad608aa4deac1e45365696a
parent bcfd3515
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -48,11 +48,13 @@
            </LinearLayout>

            <LinearLayout
                android:id="@+id/header_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginEnd="16dp"
                android:orientation="vertical">

                <TextView
                    android:id="@+id/header_title"
                    android:layout_width="wrap_content"
@@ -68,7 +70,6 @@
                    android:layout_height="wrap_content"
                    android:ellipsize="end"
                    android:maxLines="1"/>

            </LinearLayout>
        </LinearLayout>

+7 −7
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.util.Log;

@@ -87,9 +86,6 @@ public class ProviderModelSlice extends WifiSlice {
        final ListBuilder listBuilder = mHelper.createListBuilder(getUri());
        if (mHelper.isAirplaneModeEnabled() && !mWifiManager.isWifiEnabled()) {
            log("Airplane mode is enabled.");
            listBuilder.setHeader(mHelper.createHeader(Settings.ACTION_AIRPLANE_MODE_SETTINGS));
            listBuilder.addGridRow(mHelper.createMessageGridRow(R.string.condition_airplane_title,
                    Settings.ACTION_AIRPLANE_MODE_SETTINGS));
            return listBuilder.build();
        }

@@ -195,10 +191,14 @@ public class ProviderModelSlice extends WifiSlice {
            MobileNetworkUtils.setMobileDataEnabled(mContext, defaultSubId, newState,
                    false /* disableOtherSubscriptions */);
        }
        doCarrierNetworkAction(isToggleAction, newState);

        final boolean isDataEnabled =
                isToggleAction ? newState : MobileNetworkUtils.isMobileDataEnabled(mContext);
        doCarrierNetworkAction(isToggleAction, isDataEnabled);
    }

    private void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
    @VisibleForTesting
    void doCarrierNetworkAction(boolean isToggleAction, boolean isDataEnabled) {
        final NetworkProviderWorker worker = getWorker();
        if (worker == null) {
            return;
@@ -209,7 +209,7 @@ public class ProviderModelSlice extends WifiSlice {
            return;
        }

        if (MobileNetworkUtils.isMobileDataEnabled(mContext)) {
        if (isDataEnabled) {
            worker.connectCarrierNetwork();
        }
    }
+47 −12
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settings.panel;
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;

import static com.android.settings.network.InternetUpdater.INTERNET_APM;
import static com.android.settings.network.InternetUpdater.INTERNET_APM_NETWORKS;
import static com.android.settings.network.NetworkProviderSettings.ACTION_NETWORK_PROVIDER_SETTINGS;

@@ -83,6 +84,9 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        mInternetUpdater.onPause();
    }

    /**
     * @return a string for the title of the Panel.
     */
    @Override
    public CharSequence getTitle() {
        if (mIsProviderModelEnabled) {
@@ -93,10 +97,21 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
        return mContext.getText(R.string.internet_connectivity_panel_title);
    }

    /**
     * @return a string for the subtitle of the Panel.
     */
    @Override
    public CharSequence getSubTitle() {
        if (mIsProviderModelEnabled && mInternetType == INTERNET_APM) {
            return mContext.getText(R.string.condition_airplane_title);
        }
        return null;
    }

    @Override
    public List<Uri> getSlices() {
        final List<Uri> uris = new ArrayList<>();
        if (Utils.isProviderModelEnabled(mContext)) {
        if (mIsProviderModelEnabled) {
            uris.add(CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI);
            uris.add(CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
        } else {
@@ -109,18 +124,21 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve

    @Override
    public Intent getSeeMoreIntent() {
        return new Intent(Utils.isProviderModelEnabled(mContext)
        return new Intent(mIsProviderModelEnabled
                ? ACTION_NETWORK_PROVIDER_SETTINGS : Settings.ACTION_WIRELESS_SETTINGS)
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    }

    @Override
    public boolean isCustomizedButtonUsed() {
        return Utils.isProviderModelEnabled(mContext);
        return mIsProviderModelEnabled;
    }

    @Override
    public CharSequence getCustomizedButtonTitle() {
        if (mInternetType == INTERNET_APM) {
            return null;
        }
        return mContext.getText(R.string.settings_button);
    }

@@ -145,18 +163,35 @@ public class InternetConnectivityPanel implements PanelContent, LifecycleObserve
     * @param internetType the internet type
     */
    public void onInternetTypeChanged(@InternetUpdater.InternetType int internetType) {
        final boolean needRefresh = internetType != mInternetType
                && (internetType == INTERNET_APM_NETWORKS
                || mInternetType == INTERNET_APM_NETWORKS);
        mInternetType = internetType;
        if (needRefresh) {
            refresh();
        }
        if (internetType == mInternetType) {
            return;
        }

    private void refresh() {
        final boolean changeToApm = (internetType == INTERNET_APM);
        final boolean changeFromApm = (mInternetType == INTERNET_APM);
        final boolean changeWithApmNetworks =
                (internetType == INTERNET_APM_NETWORKS || mInternetType == INTERNET_APM_NETWORKS);
        mInternetType = internetType;

        if (mCallback != null) {
            if (changeToApm) {
                // The internet type is changed to the airplane mode.
                //   Title: Internet
                //   Sub-Title: Airplane mode is on
                //   Settings button: Hide
                mCallback.onHeaderChanged();
                mCallback.onCustomizedButtonStateChanged();
            } else if (changeFromApm) {
                // The internet type is changed from the airplane mode.
                //   Title: Internet
                //   Settings button: Show
                mCallback.onTitleChanged();
                mCallback.onCustomizedButtonStateChanged();
            } else if (changeWithApmNetworks) {
                // The internet type is changed with the airplane mode networks.
                //   Title: Airplane mode networks / Internet
                mCallback.onTitleChanged();
            }
        }
    }
}
+33 −27
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -94,6 +95,7 @@ public class PanelFragment extends Fragment {
    private LinearLayout mPanelHeader;
    private ImageView mTitleIcon;
    private LinearLayout mTitleGroup;
    private LinearLayout mHeaderLayout;
    private TextView mHeaderTitle;
    private TextView mHeaderSubtitle;
    private int mMaxHeight;
@@ -202,6 +204,7 @@ public class PanelFragment extends Fragment {
        mPanelHeader = mLayoutView.findViewById(R.id.panel_header);
        mTitleIcon = mLayoutView.findViewById(R.id.title_icon);
        mTitleGroup = mLayoutView.findViewById(R.id.title_group);
        mHeaderLayout = mLayoutView.findViewById(R.id.header_layout);
        mHeaderTitle = mLayoutView.findViewById(R.id.header_title);
        mHeaderSubtitle = mLayoutView.findViewById(R.id.header_subtitle);
        mFooterDivider = mLayoutView.findViewById(R.id.footer_divider);
@@ -239,13 +242,12 @@ public class PanelFragment extends Fragment {

        final IconCompat icon = mPanel.getIcon();
        final CharSequence title = mPanel.getTitle();
        final CharSequence subtitle = mPanel.getSubTitle();

        if (icon != null) {
            enablePanelHeader(icon, title);
        if (icon != null || (subtitle != null && subtitle.length() > 0)) {
            enablePanelHeader(icon, title, subtitle);
        } else {
            mTitleView.setVisibility(View.VISIBLE);
            mPanelHeader.setVisibility(View.GONE);
            mTitleView.setText(title);
            enableTitle(title);
        }

        mFooterDivider.setVisibility(View.GONE);
@@ -254,13 +256,7 @@ public class PanelFragment extends Fragment {
        mDoneButton.setOnClickListener(getCloseListener());

        if (mPanel.isCustomizedButtonUsed()) {
            final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
            if (TextUtils.isEmpty(customTitle)) {
                mSeeMoreButton.setVisibility(View.GONE);
            } else {
                mSeeMoreButton.setVisibility(View.VISIBLE);
                mSeeMoreButton.setText(customTitle);
            }
            enableCustomizedButton();
        } else if (mPanel.getSeeMoreIntent() == null) {
            // If getSeeMoreIntent() is null hide the mSeeMoreButton.
            mSeeMoreButton.setVisibility(View.GONE);
@@ -275,14 +271,16 @@ public class PanelFragment extends Fragment {
                0 /* value */);
    }

    private void enablePanelHeader(IconCompat icon, CharSequence title) {
    private void enablePanelHeader(IconCompat icon, CharSequence title, CharSequence subtitle) {
        mTitleView.setVisibility(View.GONE);
        mPanelHeader.setVisibility(View.VISIBLE);
        mPanelHeader.setAccessibilityPaneTitle(title);
        mHeaderTitle.setText(title);
        mHeaderSubtitle.setText(mPanel.getSubTitle());
        mHeaderSubtitle.setText(subtitle);
        mHeaderSubtitle.setAccessibilityPaneTitle(subtitle);
        if (icon != null) {
            mTitleGroup.setVisibility(View.VISIBLE);
            mHeaderLayout.setGravity(Gravity.LEFT);
            mTitleIcon.setImageIcon(icon.toIcon(getContext()));
            if (mPanel.getHeaderIconIntent() != null) {
                mTitleIcon.setOnClickListener(getHeaderIconListener());
@@ -295,6 +293,24 @@ public class PanelFragment extends Fragment {
            }
        } else {
            mTitleGroup.setVisibility(View.GONE);
            mHeaderLayout.setGravity(Gravity.CENTER_HORIZONTAL);
        }
    }

    private void enableTitle(CharSequence title) {
        mPanelHeader.setVisibility(View.GONE);
        mTitleView.setVisibility(View.VISIBLE);
        mTitleView.setAccessibilityPaneTitle(title);
        mTitleView.setText(title);
    }

    private void enableCustomizedButton() {
        final CharSequence customTitle = mPanel.getCustomizedButtonTitle();
        if (TextUtils.isEmpty(customTitle)) {
            mSeeMoreButton.setVisibility(View.GONE);
        } else {
            mSeeMoreButton.setVisibility(View.VISIBLE);
            mSeeMoreButton.setText(customTitle);
        }
    }

@@ -487,24 +503,14 @@ public class PanelFragment extends Fragment {
        @Override
        public void onCustomizedButtonStateChanged() {
            ThreadUtils.postOnMainThread(() -> {
                mSeeMoreButton.setVisibility(
                        mPanel.isCustomizedButtonUsed() ? View.VISIBLE : View.GONE);
                mSeeMoreButton.setText(mPanel.getCustomizedButtonTitle());
                enableCustomizedButton();
            });
        }

        @Override
        public void onHeaderChanged() {
            ThreadUtils.postOnMainThread(() -> {
                final IconCompat icon = mPanel.getIcon();
                if (icon != null) {
                    mTitleIcon.setImageIcon(icon.toIcon(getContext()));
                    mTitleGroup.setVisibility(View.VISIBLE);
                } else {
                    mTitleGroup.setVisibility(View.GONE);
                }
                mHeaderTitle.setText(mPanel.getTitle());
                mHeaderSubtitle.setText(mPanel.getSubTitle());
                enablePanelHeader(mPanel.getIcon(), mPanel.getTitle(), mPanel.getSubTitle());
            });
        }

@@ -517,7 +523,7 @@ public class PanelFragment extends Fragment {
        @Override
        public void onTitleChanged() {
            ThreadUtils.postOnMainThread(() -> {
                mTitleView.setText(mPanel.getTitle());
                enableTitle(mPanel.getTitle());
            });
        }

+0 −83
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.panel;

import static com.google.common.truth.Truth.assertThat;

import android.net.Uri;
import android.os.SystemProperties;

import com.android.settings.network.AirplaneModePreferenceController;
import com.android.settings.slices.CustomSliceRegistry;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.List;

@RunWith(RobolectricTestRunner.class)

public class InternetConnectivityPanelTest {

    private InternetConnectivityPanel mPanel;
    private static final String SETTINGS_PROVIDER_MODEL =
            "persist.sys.fflag.override.settings_provider_model";
    private boolean mSettingsProviderModelState;

    @Before
    public void setUp() {
        mPanel = InternetConnectivityPanel.create(RuntimeEnvironment.application);
        mSettingsProviderModelState = SystemProperties.getBoolean(SETTINGS_PROVIDER_MODEL, false);
    }

    @After
    public void tearDown() {
        SystemProperties.set(SETTINGS_PROVIDER_MODEL,
                mSettingsProviderModelState ? "true" : "false");
    }

    @Test
    public void getSlices_providerModelDisabled_containsNecessarySlices() {
        SystemProperties.set(SETTINGS_PROVIDER_MODEL, "false");
        final List<Uri> uris = mPanel.getSlices();

        assertThat(uris).containsExactly(
                AirplaneModePreferenceController.SLICE_URI,
                CustomSliceRegistry.MOBILE_DATA_SLICE_URI,
                CustomSliceRegistry.WIFI_SLICE_URI);
    }

    @Test
    public void getSlices_providerModelEnabled_containsNecessarySlices() {
        SystemProperties.set(SETTINGS_PROVIDER_MODEL, "true");
        final List<Uri> uris = mPanel.getSlices();

        assertThat(uris).containsExactly(
                CustomSliceRegistry.PROVIDER_MODEL_SLICE_URI,
                CustomSliceRegistry.AIRPLANE_SAFE_NETWORKS_SLICE_URI);
    }

    @Test
    public void getSeeMoreIntent_notNull() {
        assertThat(mPanel.getSeeMoreIntent()).isNotNull();
    }
}
Loading