Snap for 5087535 from d7a2569034 to qt-release

Change-Id: Ieb716b788126dafac93d8cb7ebb8d8b7f6c9f40d
This commit is contained in:
android-build-team Robot
2018-10-24 03:14:53 +00:00
19 changed files with 241 additions and 232 deletions

View File

@@ -26,7 +26,7 @@
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_height="@dimen/condition_header_height"
android:layout_centerHorizontal="true">
<FrameLayout

View File

@@ -25,7 +25,7 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="36dp"
android:minHeight="@dimen/condition_header_height"
android:background="?android:attr/selectableItemBackground"
android:orientation="horizontal">

View File

@@ -15,8 +15,43 @@
limitations under the License.
-->
<androidx.recyclerview.widget.RecyclerView
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
android:id="@+id/suggestion_footer"
android:layout_width="match_parent"
android:layout_height="@dimen/condition_header_height"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/expand_indicator"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:paddingTop="4dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"/>
<TextView
android:id="@+id/expand_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_toStartOf="@id/expand_indicator"
android:layout_centerVertical="true"
android:gravity="end"
android:textAppearance="@style/TextAppearance.SuggestionTitle"
android:textColor="?android:attr/colorAccent"/>
</RelativeLayout>
<include layout="@layout/horizontal_divider"/>
</LinearLayout>

View File

@@ -15,44 +15,28 @@
limitations under the License.
-->
<LinearLayout
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/homepage_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<include layout="@layout/search_bar"/>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="@id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
app:itemIconTint="@color/bottom_navigation_colors"
app:itemTextColor="@color/bottom_navigation_colors"
app:menu="@menu/home_bottom_navigation"/>
android:orientation="vertical"
android:descendantFocusability="blocksDescendants">
</LinearLayout>
<include layout="@layout/search_bar"/>
<FrameLayout
android:id="@+id/suggestion_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

View File

@@ -311,6 +311,7 @@
<!-- Suggestion/condition header padding -->
<dimen name="suggestion_condition_header_padding_collapsed">10dp</dimen>
<dimen name="suggestion_condition_header_padding_expanded">5dp</dimen>
<dimen name="condition_header_height">36dp</dimen>
<!-- Suggestion cards size and padding -->
<dimen name="suggestion_card_icon_size">24dp</dimen>
@@ -357,4 +358,6 @@
<!-- Signal icon in NetworkSelectSetting -->
<dimen name="signal_strength_icon_size">24dp</dimen>
</resources>

View File

@@ -10271,4 +10271,9 @@
<!-- Used for EmergencyInfoSlice slice helper class -->
<string name="emergency_info_contextual_card_summary" translatable="false">Medical info, emergency contacts</string>
<!-- See more items in contextual homepage [CHAR LIMIT=30]-->
<string name="see_more">See more</string>
<!-- See less items in contextual homepage [CHAR LIMIT=30]-->
<string name="see_less">See less</string>
</resources>

View File

@@ -99,7 +99,7 @@
</PreferenceCategory>
<ListPreference
<com.android.settings.network.telephony.cdma.CdmaListPreference
android:key="cdma_system_select_key"
android:title="@string/cdma_system_select_title"
android:summary="@string/cdma_system_select_summary"
@@ -108,7 +108,7 @@
android:dialogTitle="@string/cdma_system_select_dialogtitle"
settings:controller="com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController"/>
<ListPreference
<com.android.settings.network.telephony.cdma.CdmaListPreference
android:key="cdma_subscription_key"
android:title="@string/cdma_subscription_title"
android:summary="@string/cdma_subscription_summary"

View File

@@ -17,7 +17,6 @@
package com.android.settings.homepage;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

View File

@@ -22,7 +22,6 @@ import android.os.Bundle;
import android.util.FeatureFlagUtils;
import android.widget.Toolbar;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@@ -32,13 +31,10 @@ import com.android.settings.core.FeatureFlags;
import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.overlay.FeatureFactory;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class SettingsHomepageActivity extends SettingsBaseActivity {
@VisibleForTesting
static final String PERSONAL_SETTINGS_TAG = "personal_settings";
private static final String ALL_SETTINGS_TAG = "all_settings";
private static final String SUGGESTION_TAG = "suggestion";
private static final String MAIN_TAG = "main";
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -58,49 +54,18 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, toolbar);
final BottomNavigationView navigation = findViewById(R.id.bottom_nav);
navigation.setOnNavigationItemSelectedListener(item -> {
switch (item.getItemId()) {
case R.id.homepage_personal_settings:
switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
ALL_SETTINGS_TAG);
return true;
case R.id.homepage_all_settings:
switchFragment(new TopLevelSettings(), ALL_SETTINGS_TAG,
PERSONAL_SETTINGS_TAG);
return true;
}
return false;
});
if (savedInstanceState == null) {
// savedInstanceState is null, this is first load.
// Default to open contextual cards.
switchFragment(new PersonalSettingsFragment(), PERSONAL_SETTINGS_TAG,
ALL_SETTINGS_TAG);
}
showFragment(new PersonalSettingsFragment(), R.id.suggestion_content, SUGGESTION_TAG);
showFragment(new TopLevelSettings(), R.id.main_content, MAIN_TAG);
}
public static boolean isDynamicHomepageEnabled(Context context) {
return FeatureFlagUtils.isEnabled(context, FeatureFlags.DYNAMIC_HOMEPAGE);
}
private void switchFragment(Fragment fragment, String showFragmentTag, String hideFragmentTag) {
private void showFragment(Fragment fragment, int id, String tag) {
final FragmentManager fragmentManager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
final Fragment hideFragment = fragmentManager.findFragmentByTag(hideFragmentTag);
if (hideFragment != null) {
fragmentTransaction.hide(hideFragment);
}
Fragment showFragment = fragmentManager.findFragmentByTag(showFragmentTag);
if (showFragment == null) {
fragmentTransaction.add(R.id.main_content, fragment, showFragmentTag);
} else {
fragmentTransaction.show(showFragment);
}
fragmentTransaction.add(id, fragment, tag);
fragmentTransaction.commit();
}
}

View File

@@ -19,6 +19,7 @@ package com.android.settings.network.telephony;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
import android.app.ActionBar;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -41,6 +42,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.MenuItem;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -73,6 +75,8 @@ public class MobileNetworkFragment extends DashboardFragment implements
private static final String LOG_TAG = "NetworkSettings";
private static final boolean DBG = true;
public static final int REQUEST_CODE_EXIT_ECM = 17;
@VisibleForTesting
static final String KEY_CLICKED_PREF = "key_clicked_pref";
//String keys for preference lookup
private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key";
@@ -123,9 +127,8 @@ public class MobileNetworkFragment extends DashboardFragment implements
//GsmUmts options and Cdma options
GsmUmtsOptions mGsmUmtsOptions;
CdmaOptions mCdmaOptions;
private Preference mClickedPreference;
private String mClickedPrefKey;
private boolean mShow4GForLTE;
private boolean mIsGlobalCdma;
private boolean mOnlyAutoSelectInHomeNW;
@@ -148,6 +151,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
return true;
}
sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
final String key = preference.getKey();
/** TODO: Refactor and get rid of the if's using subclasses */
if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
@@ -155,16 +159,13 @@ public class MobileNetworkFragment extends DashboardFragment implements
} else if (mGsmUmtsOptions != null &&
mGsmUmtsOptions.preferenceTreeClick(preference) == true) {
return true;
} else if (mCdmaOptions != null &&
mCdmaOptions.preferenceTreeClick(preference) == true) {
} else if (TextUtils.equals(key, BUTTON_CDMA_SYSTEM_SELECT_KEY)
|| TextUtils.equals(key, BUTTON_CDMA_SUBSCRIPTION_KEY)) {
if (mTelephonyManager.getEmergencyCallbackMode()) {
mClickedPreference = preference;
// In ECM mode launch ECM app dialog
startActivityForResult(
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
REQUEST_CODE_EXIT_ECM);
mClickedPrefKey = key;
}
return true;
}
@@ -262,6 +263,15 @@ public class MobileNetworkFragment extends DashboardFragment implements
updatePhone();
Log.i(LOG_TAG, "onCreate:-");
onRestoreInstance(icicle);
}
@VisibleForTesting
void onRestoreInstance(Bundle icicle) {
if (icicle != null) {
mClickedPrefKey = icicle.getString(KEY_CLICKED_PREF);
}
}
@Override
@@ -342,6 +352,12 @@ public class MobileNetworkFragment extends DashboardFragment implements
return null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putString(KEY_CLICKED_PREF, mClickedPrefKey);
}
private boolean hasActiveSubscriptions() {
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
}
@@ -405,9 +421,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
== ServiceState.STATE_IN_SERVICE) {
final int phoneType = mTelephonyManager.getPhoneType();
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
updateCdmaOptions(this, prefSet, mSubId);
} else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
updateGsmUmtsOptions(this, prefSet, phoneSubId);
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
@@ -420,7 +434,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
// set the listener for the mButtonPreferredNetworkMode list preference so we can issue
// change Preferred Network Mode.
updateCdmaOptions(this, prefSet, mSubId);
updateGsmUmtsOptions(this, prefSet, phoneSubId);
}
@@ -513,33 +526,17 @@ public class MobileNetworkFragment extends DashboardFragment implements
return true;
}
private boolean is4gLtePrefEnabled(PersistableBundle carrierConfig) {
return (mTelephonyManager.getCallState(mSubId)
== TelephonyManager.CALL_STATE_IDLE)
&& mImsMgr != null
&& mImsMgr.isNonTtyOrTtyOnVolteEnabled()
&& carrierConfig.getBoolean(
CarrierConfigManager.KEY_EDITABLE_ENHANCED_4G_LTE_BOOL);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_EXIT_ECM:
Boolean isChoiceYes = data.getBooleanExtra(
EXTRA_EXIT_ECM_RESULT, false);
if (isChoiceYes) {
// If the phone exits from ECM mode, show the CDMA Options
final String key = mClickedPreference.getKey();
if (TextUtils.equals(key,
mCdmaSystemSelectPreferenceController.getPreferenceKey())) {
mCdmaSystemSelectPreferenceController.showDialog();
} else if (TextUtils.equals(key,
mCdmaSubscriptionPreferenceController.getPreferenceKey())) {
mCdmaSubscriptionPreferenceController.showDialog();
if (resultCode != Activity.RESULT_CANCELED) {
// If the phone exits from ECM mode, show the CDMA
final Preference preference = getPreferenceScreen()
.findPreference(mClickedPrefKey);
if (preference != null) {
preference.performClick();
}
} else {
// do nothing
}
break;
@@ -624,14 +621,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
}
}
private void controlCdmaOptions(boolean enable) {
PreferenceScreen prefSet = getPreferenceScreen();
if (prefSet == null) {
return;
}
updateCdmaOptions(this, prefSet, mSubId);
}
private boolean isSupportTdscdma() {
if (getResources().getBoolean(R.bool.config_support_tdscdma)) {
return true;
@@ -733,16 +722,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
}
}
private void updateCdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
int subId) {
// We don't want to re-create CdmaOptions if already exists. Otherwise, the preferences
// inside it will also be re-created which causes unexpected behavior. For example,
// the open dialog gets dismissed or detached after pause / resume.
if (mCdmaOptions == null) {
mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, subId);
}
}
private static Intent buildPhoneAccountConfigureIntent(
Context context, PhoneAccountHandle accountHandle) {
Intent intent = buildConfigureIntent(

View File

@@ -82,6 +82,9 @@ public abstract class CdmaBasePreferenceController extends BasePreferenceControl
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
if (mPreference instanceof CdmaListPreference) {
((CdmaListPreference) mPreference).setSubId(mSubId);
}
}
/**

View File

@@ -0,0 +1,46 @@
/*
* 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.network.telephony.cdma;
import android.content.Context;
import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import androidx.preference.ListPreference;
/**
* {@link ListPreference} that will launch ECM dialog when in ECM mode
*/
public class CdmaListPreference extends ListPreference {
private TelephonyManager mTelephonyManager;
public CdmaListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onClick() {
// Only show dialog when it is not in ECM
if (mTelephonyManager == null || !mTelephonyManager.getEmergencyCallbackMode()) {
super.onClick();
}
}
public void setSubId(int subId) {
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
}
}

View File

@@ -77,14 +77,6 @@ public class CdmaSubscriptionPreferenceController extends CdmaBasePreferenceCont
return false;
}
public void showDialog() {
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.PREFERRED_CDMA_SUBSCRIPTION);
mPreference.setValue(Integer.toString(mode));
mPreferenceManager.showDialog(mPreference);
}
@VisibleForTesting
boolean deviceSupportsNvAndRuim() {
// retrieve the list of subscription types supported by device.

View File

@@ -62,12 +62,6 @@ public class CdmaSystemSelectPreferenceController extends CdmaBasePreferenceCont
return false;
}
public void showDialog() {
if (!mTelephonyManager.getEmergencyCallbackMode()) {
mPreferenceManager.showDialog(mPreference);
}
}
private void resetCdmaRoamingModeToDefault() {
final ListPreference listPreference = (ListPreference) mPreference;
//set the mButtonCdmaRoam

View File

@@ -41,6 +41,7 @@ import android.text.Editable;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.FeatureFlagUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
@@ -155,6 +156,7 @@ public class WifiConfigController implements TextWatcher,
private Spinner mProxySettingsSpinner;
private Spinner mMeteredSettingsSpinner;
private Spinner mHiddenSettingsSpinner;
private Spinner mPrivacySettingsSpinner;
private TextView mHiddenWarningView;
private TextView mProxyHostView;
private TextView mProxyPortView;
@@ -220,6 +222,12 @@ public class WifiConfigController implements TextWatcher,
mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
mHiddenSettingsSpinner = mView.findViewById(R.id.hidden_settings);
mPrivacySettingsSpinner = mView.findViewById(R.id.privacy_settings);
if (FeatureFlagUtils.isEnabled(mContext,
com.android.settings.core.FeatureFlags.WIFI_MAC_RANDOMIZATION)) {
View privacySettingsLayout = mView.findViewById(R.id.privacy_settings_fields);
privacySettingsLayout.setVisibility(View.VISIBLE);
}
mHiddenSettingsSpinner.setOnItemSelectedListener(this);
mHiddenWarningView = mView.findViewById(R.id.hidden_settings_warning);
mHiddenWarningView.setVisibility(
@@ -261,6 +269,7 @@ public class WifiConfigController implements TextWatcher,
mHiddenSettingsSpinner.setSelection(config.hiddenSSID
? HIDDEN_NETWORK
: NOT_HIDDEN_NETWORK);
//TODO(b/117957974): set MAC randomization value to mPrivacySettingsSpinner
if (config.getIpAssignment() == IpAssignment.STATIC) {
mIpSettingsSpinner.setSelection(STATIC_IP);
showAdvancedFields = true;
@@ -702,6 +711,10 @@ public class WifiConfigController implements TextWatcher,
config.meteredOverride = mMeteredSettingsSpinner.getSelectedItemPosition();
}
if (mPrivacySettingsSpinner != null) {
//TODO(b/117957974): set MAC randomization value to WifiConfiguration
}
return config;
}

View File

@@ -19,7 +19,6 @@ package com.android.settings.wifi;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
import android.view.View;
import android.widget.Button;
@@ -94,14 +93,6 @@ public class WifiDialog extends AlertDialog implements WifiConfigUiBase,
if (mAccessPoint == null) {
mController.hideForgetButton();
}
if (FeatureFlagUtils.isEnabled(getContext(),
com.android.settings.core.FeatureFlags.WIFI_MAC_RANDOMIZATION)) {
View view = mView.findViewById(R.id.privacy_settings_fields);
if (view != null) {
view.setVisibility(View.VISIBLE);
}
}
}
public void onRestoreInstanceState(Bundle savedInstanceState) {

View File

@@ -1095,7 +1095,7 @@ public class WifiSettings extends RestrictedSettingsFragment
protected void connect(final WifiConfiguration config, boolean isSavedNetwork) {
// Log subtype if configuration is a saved network.
mMetricsFeatureProvider.action(getVisibilityLogger(), MetricsEvent.ACTION_WIFI_CONNECT,
mMetricsFeatureProvider.action(getContext(), MetricsEvent.ACTION_WIFI_CONNECT,
isSavedNetwork);
mWifiManager.connect(config, mConnectListener);
mClickedConnect = true;
@@ -1110,7 +1110,7 @@ public class WifiSettings extends RestrictedSettingsFragment
@VisibleForTesting
void handleAddNetworkRequest(int result, Intent data) {
if(result == Activity.RESULT_OK) {
if (result == Activity.RESULT_OK) {
handleAddNetworkSubmitEvent(data);
}
mWifiTracker.resumeScanning();

View File

@@ -0,0 +1,71 @@
/*
* 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.network.telephony.cdma;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.telephony.TelephonyManager;
import androidx.preference.PreferenceManager;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
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;
@RunWith(SettingsRobolectricTestRunner.class)
public class CdmaListPreferenceTest {
private static final int SUB_ID = 2;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private PreferenceManager mPreferenceManager;
private CdmaListPreference mPreference;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mTelephonyManager).when(mContext).getSystemService(TelephonyManager.class);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
mPreference = spy(new CdmaListPreference(mContext, null));
mPreference.setSubId(SUB_ID);
}
@Test
public void onClick_inEcm_doNothing() {
doReturn(true).when(mTelephonyManager).getEmergencyCallbackMode();
mPreference.onClick();
verify(mPreferenceManager, never()).showDialog(mPreference);
}
}

View File

@@ -1,71 +0,0 @@
/*
* 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.homepage;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.android.settings.homepage.SettingsHomepageActivity.PERSONAL_SETTINGS_TAG;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.content.Intent;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.FeatureFlagUtils;
import androidx.fragment.app.Fragment;
import com.android.settings.core.FeatureFlags;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class SettingsHomepageActivityTest {
private Context mContext;
private SettingsHomepageActivity mActivity;
@Before
public void setUp() {
mContext = InstrumentationRegistry.getTargetContext();
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DYNAMIC_HOMEPAGE, true);
}
@After
public void tearDown() {
FeatureFlagUtils.setEnabled(mContext, FeatureFlags.DYNAMIC_HOMEPAGE, false);
}
@Test
public void launchHomepage_shouldOpenPersonalSettings() {
final Intent intent = new Intent().setClass(mContext, SettingsHomepageActivity.class)
.addFlags(FLAG_ACTIVITY_NEW_TASK);
mActivity = (SettingsHomepageActivity) InstrumentationRegistry.getInstrumentation()
.startActivitySync(intent);
final Fragment fragment = mActivity.getSupportFragmentManager()
.findFragmentByTag(PERSONAL_SETTINGS_TAG);
assertThat(fragment).isInstanceOf(PersonalSettingsFragment.class);
}
}