Snap for 5067452 from d69be7df8d to qt-release

Change-Id: I4ad4555f02b27654524a1cca8d48d220ea7e7475
This commit is contained in:
android-build-team Robot
2018-10-14 03:15:46 +00:00
58 changed files with 933 additions and 487 deletions

View File

@@ -32,7 +32,6 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
com.google.android.material_material \
LOCAL_JAVA_LIBRARIES := \
bouncycastle \
telephony-common \
ims-common

View File

@@ -131,7 +131,7 @@
android:launchMode="singleTask">
</activity>
<activity android:name=".mobilenetwork.MobileSettingsActivity"
<activity android:name=".network.telephony.MobileSettingsActivity"
android:label="@string/network_settings_title"
android:theme="@style/Theme.Settings.Home"
android:launchMode="singleTask">

View File

@@ -19,4 +19,4 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_container"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="match_parent" />

View File

@@ -15,11 +15,34 @@
limitations under the License.
-->
<RelativeLayout
<LinearLayout
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:layout_height="match_parent"
android:orientation="vertical">
<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"
@@ -28,25 +51,8 @@
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:itemIconTint="@color/bottom_navigation_colors"
app:itemTextColor="@color/bottom_navigation_colors"
app:menu="@menu/home_bottom_navigation" />
app:menu="@menu/home_bottom_navigation"/>
<FrameLayout
android:id="@id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_nav" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/search_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_24dp"
android:layout_margin="24dp"
android:layout_above="@id/bottom_nav"
android:layout_alignParentRight="true"
app:backgroundTint="?android:attr/colorAccent"
app:tint="@android:color/white" />
</RelativeLayout>
</LinearLayout>

View File

@@ -18,6 +18,7 @@
<resources>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">
<item name="colorPrimary">@*android:color/primary_device_default_settings</item>
<item name="colorPrimaryDark">@*android:color/primary_dark_device_default_settings</item>
</style>

View File

@@ -170,6 +170,9 @@
<item name="colorPrimary">@*android:color/primary_device_default_settings_light</item>
<item name="colorAccent">@*android:color/accent_device_default_light</item>
<item name="preferenceTheme">@style/PreferenceTheme</item>
<!-- action bar, needed for search bar icon tinting -->
<item name="android:actionBarTheme">@*android:style/ThemeOverlay.DeviceDefault.ActionBar.Accent</item>
</style>
<style name="Theme.Settings.Home" parent="Theme.Settings.HomeBase">

View File

@@ -17,7 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.settings.mobilenetwork.CdmaSystemSelectListPreference
<com.android.settings.network.telephony.CdmaSystemSelectListPreference
android:key="cdma_system_select_key"
android:title="@string/cdma_system_select_title"
android:summary="@string/cdma_system_select_summary"
@@ -25,7 +25,7 @@
android:entryValues="@array/cdma_system_select_values"
android:dialogTitle="@string/cdma_system_select_dialogtitle" />
<com.android.settings.mobilenetwork.CdmaSubscriptionListPreference
<com.android.settings.network.telephony.CdmaSubscriptionListPreference
android:key="cdma_subscription_key"
android:title="@string/cdma_subscription_title"
android:summary="@string/cdma_subscription_summary"

View File

@@ -17,7 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.settings.mobilenetwork.NetworkOperators
<com.android.settings.network.telephony.NetworkOperators
android:key="network_operators_category_key"
android:title="@string/network_operator_category"
android:persistent="false">
@@ -36,7 +36,7 @@
android:key="button_choose_network_key"
android:title="@string/choose_network_title"
android:fragment="com.android.phone.NetworkSelectSetting" />
</com.android.settings.mobilenetwork.NetworkOperators>
</com.android.settings.network.telephony.NetworkOperators>
<!--We want separate APN setting from reset of settings because-->
<!--we want user to change it with caution.-->

View File

@@ -16,6 +16,8 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="mobile_network_pref_screen"
android:title="@string/network_settings_title"
settings:initialExpandedChildrenCount="4">
<PreferenceScreen
@@ -23,10 +25,11 @@
android:title="@string/cdma_lte_data_service">
</PreferenceScreen>
<com.android.settings.mobilenetwork.MobileDataPreference
<SwitchPreference
android:key="mobile_data_enable"
android:title="@string/mobile_data_settings_title"
android:summary="@string/mobile_data_settings_summary"/>
android:summary="@string/mobile_data_settings_summary"
settings:controller="com.android.settings.network.telephony.MobileDataPreferenceController"/>
<com.android.settingslib.RestrictedSwitchPreference
android:key="button_roaming_key"
@@ -35,7 +38,7 @@
android:summaryOn="@string/roaming_enable"
android:summaryOff="@string/roaming_disable"/>
<com.android.settings.mobilenetwork.DataUsagePreference
<com.android.settings.network.telephony.DataUsagePreference
android:key="data_usage_summary"
android:title="@string/data_usage_title" />

View File

@@ -35,6 +35,7 @@ import android.net.NetworkRequest;
import android.net.TrafficStats;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -1359,25 +1360,26 @@ public class RadioInfo extends Activity {
imsVolteProvisionedSwitch.setOnCheckedChangeListener(null);
imsVolteProvisionedSwitch.setChecked(isImsVolteProvisioned());
imsVolteProvisionedSwitch.setOnCheckedChangeListener(mImsVolteCheckedChangeListener);
imsVolteProvisionedSwitch.setEnabled(
mImsManager.isVolteEnabledByPlatform(phone.getContext()));
imsVolteProvisionedSwitch.setEnabled(!Build.IS_USER
&& mImsManager.isVolteEnabledByPlatform(phone.getContext()));
imsVtProvisionedSwitch.setOnCheckedChangeListener(null);
imsVtProvisionedSwitch.setChecked(isImsVtProvisioned());
imsVtProvisionedSwitch.setOnCheckedChangeListener(mImsVtCheckedChangeListener);
imsVtProvisionedSwitch.setEnabled(
mImsManager.isVtEnabledByPlatform(phone.getContext()));
imsVtProvisionedSwitch.setEnabled(!Build.IS_USER
&& mImsManager.isVtEnabledByPlatform(phone.getContext()));
imsWfcProvisionedSwitch.setOnCheckedChangeListener(null);
imsWfcProvisionedSwitch.setChecked(isImsWfcProvisioned());
imsWfcProvisionedSwitch.setOnCheckedChangeListener(mImsWfcCheckedChangeListener);
imsWfcProvisionedSwitch.setEnabled(
mImsManager.isWfcEnabledByPlatform(phone.getContext()));
imsWfcProvisionedSwitch.setEnabled(!Build.IS_USER
&& mImsManager.isWfcEnabledByPlatform(phone.getContext()));
eabProvisionedSwitch.setOnCheckedChangeListener(null);
eabProvisionedSwitch.setChecked(isEabProvisioned());
eabProvisionedSwitch.setOnCheckedChangeListener(mEabCheckedChangeListener);
eabProvisionedSwitch.setEnabled(isEabEnabledByPlatform(phone.getContext()));
eabProvisionedSwitch.setEnabled(!Build.IS_USER
&& isEabEnabledByPlatform(phone.getContext()));
}
OnClickListener mDnsCheckButtonHandler = new OnClickListener() {

View File

@@ -299,15 +299,6 @@ public class SettingsActivity extends SettingsBaseActivity
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, toolbar);
setActionBar(toolbar);
// Please forgive me for what I am about to do.
//
// Need to make the navigation icon non-clickable so that the entire card is clickable
// and goes to the search UI. Also set the background to null so there's no ripple.
View navView = toolbar.getNavigationView();
navView.setClickable(false);
navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
navView.setBackground(null);
}
ActionBar actionBar = getActionBar();

View File

@@ -30,6 +30,7 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.applications.ProcStatsData.MemInfo;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.instrumentation.Instrumentable;
import com.android.settingslib.widget.settingsspinner.SettingsSpinnerAdapter;
public abstract class ProcessStatsBase extends SettingsPreferenceFragment
implements OnItemSelectedListener {
@@ -104,9 +105,8 @@ public abstract class ProcessStatsBase extends SettingsPreferenceFragment
super.onViewCreated(view, savedInstanceState);
mSpinnerHeader = (ViewGroup) setPinnedHeaderView(R.layout.apps_filter_spinner);
mFilterSpinner = (Spinner) mSpinnerHeader.findViewById(R.id.filter_spinner);
mFilterAdapter = new ArrayAdapter<String>(mFilterSpinner.getContext(),
R.layout.filter_spinner_item);
mFilterAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mFilterAdapter = new SettingsSpinnerAdapter<String>(mFilterSpinner.getContext());
for (int i = 0; i < NUM_DURATIONS; i++) {
mFilterAdapter.add(getString(sDurationLabels[i]));
}

View File

@@ -171,6 +171,11 @@ public class FaceEnrollEnrolling extends BiometricsEnrollEnrolling {
// TODO: Update the actual animation
showError("Steps: " + steps + " Remaining: " + remaining);
// TODO: Have this match any animations that UX comes up with
if (remaining == 0) {
launchFinish(mToken);
}
}
@Override

View File

@@ -85,9 +85,13 @@ public class StorageWizardMigrateConfirm extends StorageWizardBase {
FeatureFactory.getFactory(this).getMetricsFeatureProvider().action(this,
MetricsEvent.ACTION_STORAGE_MIGRATE_LATER);
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(EXTRA_MIGRATE_SKIP, true);
startActivity(intent);
if (mDisk != null) {
final Intent intent = new Intent(this, StorageWizardReady.class);
intent.putExtra(EXTRA_MIGRATE_SKIP, true);
startActivity(intent);
} else {
finishAffinity();
}
}
@Override

View File

@@ -20,6 +20,7 @@ import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.FeatureFlagUtils;
import android.widget.Toolbar;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
@@ -32,7 +33,6 @@ import com.android.settings.core.SettingsBaseActivity;
import com.android.settings.overlay.FeatureFactory;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
public class SettingsHomepageActivity extends SettingsBaseActivity {
@@ -54,9 +54,9 @@ public class SettingsHomepageActivity extends SettingsBaseActivity {
setContentView(R.layout.settings_homepage_container);
final FloatingActionButton searchButton = findViewById(R.id.search_fab);
final Toolbar toolbar = findViewById(R.id.search_action_bar);
FeatureFactory.getFactory(this).getSearchFeatureProvider()
.initSearchToolbar(this, searchButton);
.initSearchToolbar(this, toolbar);
final BottomNavigationView navigation = findViewById(R.id.bottom_nav);
navigation.setOnNavigationItemSelectedListener(item -> {

View File

@@ -82,6 +82,7 @@ public class SliceContextualCardRenderer implements ContextualCardRenderer,
return;
}
cardHolder.sliceView.setScrollable(false);
cardHolder.sliceView.setTag(uri);
//TODO(b/114009676): We will soon have a field to decide what slice mode we should set.
cardHolder.sliceView.setMode(SliceView.MODE_LARGE);

View File

@@ -215,7 +215,7 @@ public class KeyboardLayoutDialogFragment extends InstrumentedDialogFragment
private void updateSwitchHintVisibility() {
AlertDialog dialog = (AlertDialog)getDialog();
if (dialog != null) {
View customPanel = dialog.findViewById(com.android.internal.R.id.customPanel);
View customPanel = dialog.findViewById(R.id.customPanel);
customPanel.setVisibility(mAdapter.getCount() > 1 ? View.VISIBLE : View.GONE);
}
}

View File

@@ -1,324 +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.mobilenetwork;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcel;
import android.os.Parcelable;
import android.provider.Settings.Global;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.widget.Checkable;
import androidx.preference.DialogPreference;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import java.util.List;
/**
* Customized Preference to enable / disable mobile data.
* Basically copy of with com.android.settings.CellDataPreference.
*/
public class MobileDataPreference extends DialogPreference implements
DialogInterface.OnClickListener {
private static final boolean DBG = false;
private static final String TAG = "MobileDataPreference";
public int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
public boolean mChecked;
// Whether to show the dialog to ask switching default data subscription.
// Should be true only when a multi-sim phone only supports data connection on a single phone,
// and user is enabling data on the non-default phone.
public boolean mMultiSimDialog;
private TelephonyManager mTelephonyManager;
private SubscriptionManager mSubscriptionManager;
public MobileDataPreference(Context context, AttributeSet attrs) {
super(context, attrs, com.android.internal.R.attr.switchPreferenceStyle);
}
// Must be called to avoid binder leakage.
void dispose() {
mListener.setListener(false, mSubId, getContext());
}
@Override
protected void onRestoreInstanceState(Parcelable s) {
CellDataState state = (CellDataState) s;
super.onRestoreInstanceState(state.getSuperState());
mTelephonyManager = TelephonyManager.from(getContext());
mChecked = state.mChecked;
mMultiSimDialog = state.mMultiSimDialog;
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mSubId = state.mSubId;
setKey(getKey() + mSubId);
}
notifyChanged();
}
@Override
protected Parcelable onSaveInstanceState() {
CellDataState state = new CellDataState(super.onSaveInstanceState());
state.mChecked = mChecked;
state.mMultiSimDialog = mMultiSimDialog;
state.mSubId = mSubId;
return state;
}
@Override
public void onAttached() {
super.onAttached();
mListener.setListener(true, mSubId, getContext());
}
@Override
protected void onPrepareForRemoval() {
mListener.setListener(false, mSubId, getContext());
super.onPrepareForRemoval();
}
/**
* Initialize this preference with subId.
*/
public void initialize(int subId) {
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
throw new IllegalArgumentException("MobileDataPreference needs a SubscriptionInfo");
}
mSubscriptionManager = SubscriptionManager.from(getContext());
mTelephonyManager = TelephonyManager.from(getContext());
if (mSubId != subId) {
mSubId = subId;
setKey(getKey() + subId);
}
updateChecked();
}
private void updateChecked() {
setChecked(mTelephonyManager.getDataEnabled(mSubId));
}
@Override
public void performClick() {
if (!isEnabled() || !SubscriptionManager.isValidSubscriptionId(mSubId)) {
return;
}
final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
mSubId);
final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
final boolean isMultiSim = (mTelephonyManager.getSimCount() > 1);
final boolean isMultipleDataOnCapable =
(mTelephonyManager.getNumberOfModemsWithSimultaneousDataConnections() > 1);
final boolean isDefaultDataSubscription = (nextSir != null && currentSir != null
&& currentSir.getSubscriptionId() == nextSir.getSubscriptionId());
if (mChecked) {
if (!isMultiSim) {
// disabling data; show confirmation dialog which eventually
// calls setMobileDataEnabled() once user confirms.
mMultiSimDialog = false;
super.performClick();
} else {
// Don't show any dialog.
setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */);
}
} else {
if (isMultiSim && !isMultipleDataOnCapable && !isDefaultDataSubscription) {
// enabling data and setting to default; show confirmation dialog which eventually
// calls setMobileDataEnabled() once user confirms.
mMultiSimDialog = true;
super.performClick();
} else {
// Don't show any dialog.
setMobileDataEnabled(true /* enabled */, false /* disableOtherSubscriptions */);
}
}
}
private void setMobileDataEnabled(boolean enabled, boolean disableOtherSubscriptions) {
if (DBG) Log.d(TAG, "setMobileDataEnabled(" + enabled + "," + mSubId + ")");
MetricsLogger.action(getContext(), MetricsEvent.ACTION_MOBILE_NETWORK_MOBILE_DATA_TOGGLE,
enabled);
mTelephonyManager.setDataEnabled(mSubId, enabled);
if (disableOtherSubscriptions) {
disableDataForOtherSubscriptions(mSubId);
}
setChecked(enabled);
}
private void setChecked(boolean checked) {
if (mChecked == checked) return;
mChecked = checked;
notifyChanged();
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
View checkableView = holder.findViewById(com.android.internal.R.id.switch_widget);
checkableView.setClickable(false);
((Checkable) checkableView).setChecked(mChecked);
}
//TODO(b/114749736): move it to preference controller
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
if (mMultiSimDialog) {
showMultiSimDialog(builder);
} else {
showDisableDialog(builder);
}
}
private void showDisableDialog(AlertDialog.Builder builder) {
builder.setTitle(null)
.setMessage(R.string.data_usage_disable_mobile)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null);
}
private void showMultiSimDialog(AlertDialog.Builder builder) {
final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
final String previousName = (nextSir == null)
? getContext().getResources().getString(R.string.sim_selection_required_pref)
: nextSir.getDisplayName().toString();
builder.setTitle(R.string.sim_change_data_title);
builder.setMessage(getContext().getString(R.string.sim_change_data_message,
String.valueOf(currentSir != null ? currentSir.getDisplayName() : null),
previousName));
builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(R.string.cancel, null);
}
private void disableDataForOtherSubscriptions(int subId) {
List<SubscriptionInfo> subInfoList = mSubscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
if (subInfo.getSubscriptionId() != subId) {
mTelephonyManager.setDataEnabled(subInfo.getSubscriptionId(), false);
}
}
}
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which != DialogInterface.BUTTON_POSITIVE) {
return;
}
if (mMultiSimDialog) {
mSubscriptionManager.setDefaultDataSubId(mSubId);
setMobileDataEnabled(true /* enabled */, true /* disableOtherSubscriptions */);
} else {
// TODO: extend to modify policy enabled flag.
setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */);
}
}
private final DataStateListener mListener = new DataStateListener() {
@Override
public void onChange(boolean selfChange) {
updateChecked();
}
};
/**
* Listener that listens mobile data state change.
*/
public abstract static class DataStateListener extends ContentObserver {
public DataStateListener() {
super(new Handler(Looper.getMainLooper()));
}
/**
* Set / Unset data state listening, specifying subId.
*/
public void setListener(boolean listening, int subId, Context context) {
if (listening) {
Uri uri = Global.getUriFor(Global.MOBILE_DATA);
if (TelephonyManager.getDefault().getSimCount() != 1) {
uri = Global.getUriFor(Global.MOBILE_DATA + subId);
}
context.getContentResolver().registerContentObserver(uri, false, this);
} else {
context.getContentResolver().unregisterContentObserver(this);
}
}
}
/**
* Class that represents state of mobile data state.
* Used by onSaveInstanceState and onRestoreInstanceState.
*/
public static class CellDataState extends BaseSavedState {
public int mSubId;
public boolean mChecked;
public boolean mMultiSimDialog;
public CellDataState(Parcelable base) {
super(base);
}
public CellDataState(Parcel source) {
super(source);
mChecked = source.readByte() != 0;
mMultiSimDialog = source.readByte() != 0;
mSubId = source.readInt();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
super.writeToParcel(dest, flags);
dest.writeByte((byte) (mChecked ? 1 : 0));
dest.writeByte((byte) (mMultiSimDialog ? 1 : 0));
dest.writeInt(mSubId);
}
public static final Creator<CellDataState> CREATOR = new Creator<CellDataState>() {
@Override
public CellDataState createFromParcel(Parcel source) {
return new CellDataState(source);
}
@Override
public CellDataState[] newArray(int size) {
return new CellDataState[size];
}
};
}
}

View File

@@ -36,7 +36,7 @@ import androidx.preference.PreferenceScreen;
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.mobilenetwork.MobileSettingsActivity;
import com.android.settings.network.telephony.MobileSettingsActivity;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedPreference;
import com.android.settingslib.Utils;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Intent;
import android.os.PersistableBundle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Context;
import android.os.Bundle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Context;
import android.os.Bundle;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;

View File

@@ -14,9 +14,8 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkTemplate;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 The Android Open Source Project
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Context;
import android.content.Intent;

View File

@@ -0,0 +1,133 @@
/*
* 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;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
/**
* Dialog Fragment to show dialog for "mobile data"
*
* 1. When user want to disable data in single sim case, show dialog to confirm
* 2. When user want to enable data in multiple sim case, show dialog to confirm to disable other
* sim
*/
public class MobileDataDialogFragment extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener {
public static final int TYPE_DISABLE_DIALOG = 0;
public static final int TYPE_MULTI_SIM_DIALOG = 1;
private static final String ARG_DIALOG_TYPE = "dialog_type";
private static final String ARG_SUB_ID = "subId";
private SubscriptionManager mSubscriptionManager;
private int mType;
private int mSubId;
public static MobileDataDialogFragment newInstance(int type, int subId) {
final MobileDataDialogFragment dialogFragment = new MobileDataDialogFragment();
Bundle args = new Bundle();
args.putInt(ARG_DIALOG_TYPE, type);
args.putInt(ARG_SUB_ID, subId);
dialogFragment.setArguments(args);
return dialogFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSubscriptionManager = getContext().getSystemService(SubscriptionManager.class);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Bundle bundle = getArguments();
final Context context = getContext();
mType = bundle.getInt(ARG_DIALOG_TYPE);
mSubId = bundle.getInt(ARG_SUB_ID);
switch (mType) {
case TYPE_DISABLE_DIALOG:
return new AlertDialog.Builder(context)
.setMessage(R.string.data_usage_disable_mobile)
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null)
.create();
case TYPE_MULTI_SIM_DIALOG:
final SubscriptionInfo currentSubInfo =
mSubscriptionManager.getActiveSubscriptionInfo(mSubId);
final SubscriptionInfo nextSubInfo =
mSubscriptionManager.getDefaultDataSubscriptionInfo();
final String previousName = (nextSubInfo == null)
? getContext().getResources().getString(
R.string.sim_selection_required_pref)
: nextSubInfo.getDisplayName().toString();
return new AlertDialog.Builder(context)
.setTitle(R.string.sim_change_data_title)
.setMessage(context.getString(R.string.sim_change_data_message,
currentSubInfo != null
? currentSubInfo.getDisplayName()
: "",
previousName))
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(R.string.cancel, null)
.create();
default:
throw new IllegalArgumentException("unknown type " + mType);
}
}
@Override
public int getMetricsCategory() {
//TODO(b/114749736): add metric id for this fragment
return 0;
}
@Override
public void onClick(DialogInterface dialog, int which) {
switch (mType) {
case TYPE_DISABLE_DIALOG:
MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, false /* enabled */,
false /* disableOtherSubscriptions */);
break;
case TYPE_MULTI_SIM_DIALOG:
mSubscriptionManager.setDefaultDataSubId(mSubId);
MobileNetworkUtils.setMobileDataEnabled(getContext(), mSubId, true /* enabled */,
true /* disableOtherSubscriptions */);
break;
default:
throw new IllegalArgumentException("unknown type " + mType);
}
}
}

View File

@@ -0,0 +1,189 @@
/*
* 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;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.core.TogglePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
/**
* Preference controller for "Mobile data"
*/
public class MobileDataPreferenceController extends TogglePreferenceController
implements LifecycleObserver, OnStart, OnStop {
private static final String DIALOG_TAG = "MobileDataDialog";
private SwitchPreference mPreference;
private TelephonyManager mTelephonyManager;
private SubscriptionManager mSubscriptionManager;
private DataContentObserver mDataContentObserver;
private FragmentManager mFragmentManager;
private int mSubId;
@VisibleForTesting
int mDialogType;
@VisibleForTesting
boolean mNeedDialog;
public MobileDataPreferenceController(Context context, String key) {
super(context, key);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
}
@Override
public int getAvailabilityStatus() {
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
}
@Override
public void onStart() {
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mDataContentObserver.register(mContext, mSubId);
}
}
@Override
public void onStop() {
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mDataContentObserver.unRegister(mContext);
}
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
if (mNeedDialog) {
showDialog(mDialogType);
}
return true;
}
return false;
}
@Override
public boolean setChecked(boolean isChecked) {
mNeedDialog = isDialogNeeded();
if (!mNeedDialog) {
// Update data directly if we don't need dialog
MobileNetworkUtils.setMobileDataEnabled(mContext, mSubId, isChecked, false);
return true;
}
return false;
}
@Override
public boolean isChecked() {
return mTelephonyManager.isDataEnabled();
}
public void init(FragmentManager fragmentManager, int subId) {
mFragmentManager = fragmentManager;
mSubId = subId;
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
}
@VisibleForTesting
boolean isDialogNeeded() {
final boolean enableData = !mTelephonyManager.isDataEnabled();
final SubscriptionInfo currentSir = mSubscriptionManager.getActiveSubscriptionInfo(
mSubId);
final SubscriptionInfo nextSir = mSubscriptionManager.getDefaultDataSubscriptionInfo();
final boolean isMultiSim = (mTelephonyManager.getSimCount() > 1);
final boolean isMultipleDataOnCapable =
(mTelephonyManager.getNumberOfModemsWithSimultaneousDataConnections() > 1);
final boolean isDefaultDataSubscription = (nextSir != null && currentSir != null
&& currentSir.getSubscriptionId() == nextSir.getSubscriptionId());
if (enableData) {
if (isMultiSim && !isMultipleDataOnCapable && !isDefaultDataSubscription) {
mDialogType = MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG;
return true;
}
} else {
if (!isMultiSim) {
mDialogType = MobileDataDialogFragment.TYPE_DISABLE_DIALOG;
return true;
}
}
return false;
}
private void showDialog(int type) {
final MobileDataDialogFragment dialogFragment = MobileDataDialogFragment.newInstance(type,
mSubId);
dialogFragment.show(mFragmentManager, DIALOG_TAG);
}
/**
* Listener that listens mobile data state change.
*/
public class DataContentObserver extends ContentObserver {
public DataContentObserver(Handler handler) {
super(handler);
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
updateState(mPreference);
}
public void register(Context context, int subId) {
Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
if (TelephonyManager.getDefault().getSimCount() != 1) {
uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
}
context.getContentResolver().registerContentObserver(uri, false, this);
}
public void unRegister(Context context) {
context.getContentResolver().unregisterContentObserver(this);
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
@@ -34,6 +34,7 @@ import android.os.Message;
import android.os.PersistableBundle;
import android.os.UserHandle;
import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
@@ -63,6 +64,7 @@ import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -156,7 +158,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
private Preference mWiFiCallingPref;
private SwitchPreference mVideoCallingPref;
private NetworkSelectListPreference mButtonNetworkSelect;
private MobileDataPreference mMobileDataPref;
private DataUsagePreference mDataUsagePref;
private static final String iface = "rmnet0"; //TODO: this will go away
@@ -238,6 +239,9 @@ public class MobileNetworkFragment extends DashboardFragment implements
*/
@Override
public boolean onPreferenceTreeClick(Preference preference) {
if (super.onPreferenceTreeClick(preference)) {
return true;
}
sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
/** TODO: Refactor and get rid of the if's using subclasses */
@@ -298,7 +302,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
startActivity(intent);
return true;
} else if (preference == mWiFiCallingPref || preference == mVideoCallingPref
|| preference == mMobileDataPref || preference == mDataUsagePref) {
|| preference == mDataUsagePref) {
return false;
} else {
// if the button is anything but the simple toggle preference,
@@ -383,6 +387,15 @@ public class MobileNetworkFragment extends DashboardFragment implements
mPhoneStateListener.updateSubscriptionId(mSubId);
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
}
@Override
public void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate:+");
@@ -407,7 +420,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
mCallingCategory = (PreferenceCategory) findPreference(CATEGORY_CALLING_KEY);
mWiFiCallingPref = findPreference(BUTTON_WIFI_CALLING_KEY);
mVideoCallingPref = (SwitchPreference) findPreference(BUTTON_VIDEO_CALLING_KEY);
mMobileDataPref = (MobileDataPreference) findPreference(BUTTON_MOBILE_DATA_ENABLE_KEY);
mDataUsagePref = (DataUsagePreference) findPreference(BUTTON_DATA_USAGE_KEY);
try {
@@ -439,8 +451,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
// Initialize mActiveSubInfo
int max = mSubscriptionManager.getActiveSubscriptionInfoCountMax();
mActiveSubInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
mSubId = getArguments().getInt(MobileSettingsActivity.KEY_SUBSCRIPTION_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
updatePhone();
if (hasActiveSubscriptions()) {
@@ -490,14 +500,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (mMobileDataPref != null) {
mMobileDataPref.dispose();
}
}
@Override
public void onResume() {
super.onResume();
@@ -567,17 +569,14 @@ public class MobileNetworkFragment extends DashboardFragment implements
actionBar.setDisplayHomeAsUpEnabled(true);
}
prefSet.addPreference(mMobileDataPref);
prefSet.addPreference(mButtonDataRoam);
prefSet.addPreference(mDataUsagePref);
mMobileDataPref.setEnabled(hasActiveSubscriptions);
mButtonDataRoam.setEnabled(hasActiveSubscriptions);
mDataUsagePref.setEnabled(hasActiveSubscriptions);
if (hasActiveSubscriptions) {
// Customized preferences needs to be initialized with subId.
mMobileDataPref.initialize(phoneSubId);
mDataUsagePref.initialize(phoneSubId);
// Initialize states of mButtonDataRoam.
@@ -609,8 +608,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
return;
}
prefSet.removeAll();
updateBodyBasicFields(activity, prefSet, mSubId, hasActiveSubscriptions);
if (hasActiveSubscriptions) {
@@ -1075,6 +1072,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
Bundle b = new Bundle();
b.putInt(RoamingDialogFragment.SUB_ID_KEY, mSubId);
fragment.setArguments(b);
fragment.setTargetFragment(this, 0 /* requestCode */);
fragment.show(getFragmentManager(), ROAMING_TAG);
// Don't update the toggle unless the confirm button is actually pressed.
return false;
@@ -1751,8 +1749,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
if (preference == null) {
return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
} else if (preference == mMobileDataPref) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_MOBILE_DATA_TOGGLE;
} else if (preference == mButtonDataRoam) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_DATA_ROAMING_TOGGLE;
} else if (preference == mDataUsagePref) {
@@ -1864,6 +1860,17 @@ public class MobileNetworkFragment extends DashboardFragment implements
protected boolean isPageSearchEnabled(Context context) {
return false;
}
@Override
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
boolean enabled) {
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
final SearchIndexableResource sir = new SearchIndexableResource(context);
sir.xmlResId = R.xml.network_setting_fragment;
result.add(sir);
return result;
}
};
private static final class SetPreferredNetworkAsyncTask extends AsyncTask<Void, Void, Boolean> {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
@@ -29,12 +29,16 @@ import android.os.SystemProperties;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
import android.telephony.ims.feature.ImsFeature;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.ims.ImsException;
import com.android.ims.ImsManager;
@@ -53,6 +57,8 @@ public class MobileNetworkUtils {
// the default value is false.
private static final String KEY_ENABLE_ESIM_UI_BY_DEFAULT =
"esim.enable_esim_system_ui_by_default";
private static final String LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT =
"android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
/**
* Returns if DPC APNs are enforced.
@@ -90,11 +96,10 @@ public class MobileNetworkUtils {
boolean isWifiCallingEnabled;
if (simCallManager != null) {
//TODO(b/114749736): build intent to query wifi calling feature
final Intent intent = null;
PackageManager pm = context.getPackageManager();
isWifiCallingEnabled = intent != null
&& !pm.queryIntentActivities(intent, 0 /* flags */).isEmpty();
Intent intent = buildPhoneAccountConfigureIntent(
context, simCallManager);
isWifiCallingEnabled = intent != null;
} else {
ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
isWifiCallingEnabled = imsMgr != null
@@ -106,6 +111,43 @@ public class MobileNetworkUtils {
return isWifiCallingEnabled;
}
@VisibleForTesting
static Intent buildPhoneAccountConfigureIntent(
Context context, PhoneAccountHandle accountHandle) {
Intent intent = buildConfigureIntent(
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
if (intent == null) {
// If the new configuration didn't work, try the old configuration intent.
intent = buildConfigureIntent(context, accountHandle,
LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT);
}
return intent;
}
private static Intent buildConfigureIntent(
Context context, PhoneAccountHandle accountHandle, String actionStr) {
if (accountHandle == null || accountHandle.getComponentName() == null
|| TextUtils.isEmpty(accountHandle.getComponentName().getPackageName())) {
return null;
}
// Build the settings intent.
Intent intent = new Intent(actionStr);
intent.setPackage(accountHandle.getComponentName().getPackageName());
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
// Check to see that the phone account package can handle the setting intent.
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
if (resolutions.size() == 0) {
intent = null; // set no intent if the package cannot handle it.
}
return intent;
}
public static boolean isImsServiceStateReady(ImsManager imsMgr) {
boolean isImsServiceStateReady = false;
@@ -170,4 +212,30 @@ public class MobileNetworkUtils {
//TODO(b/114749736): get carrier config from subId
return new PersistableBundle();
}
/**
* Set whether to enable data for {@code subId}, also whether to disable data for other
* subscription
*/
public static void setMobileDataEnabled(Context context, int subId, boolean enabled,
boolean disableOtherSubscriptions) {
final TelephonyManager telephonyManager = TelephonyManager.from(context)
.createForSubscriptionId(subId);
final SubscriptionManager subscriptionManager = context.getSystemService(
SubscriptionManager.class);
telephonyManager.setDataEnabled(enabled);
if (disableOtherSubscriptions) {
List<SubscriptionInfo> subInfoList =
subscriptionManager.getActiveSubscriptionInfoList();
if (subInfoList != null) {
for (SubscriptionInfo subInfo : subInfoList) {
if (subInfo.getSubscriptionId() != subId) {
TelephonyManager.from(context).createForSubscriptionId(
subInfo.getSubscriptionId()).setDataEnabled(false);
}
}
}
}
}
}

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Intent;
import android.os.Bundle;
@@ -23,6 +23,12 @@ import android.telephony.SubscriptionManager;
import android.view.Menu;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
import com.android.settings.core.SettingsBaseActivity;
@@ -31,23 +37,28 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
public class MobileSettingsActivity extends SettingsBaseActivity {
@VisibleForTesting
static final String MOBILE_SETTINGS_TAG = "mobile_settings:";
public static final String KEY_SUBSCRIPTION_ID = "key_subscription_id";
public static final String KEY_CUR_SUBSCRIPTION_ID = "key_cur_subscription_id";
private SubscriptionManager mSubscriptionManager;
@VisibleForTesting
int mPrevSubscriptionId;
Integer mCurSubscriptionId;
@VisibleForTesting
List<SubscriptionInfo> mSubscriptionInfos;
private final SubscriptionManager.OnSubscriptionsChangedListener
mOnSubscriptionsChangeListener
= new SubscriptionManager.OnSubscriptionsChangedListener() {
@Override
public void onSubscriptionsChanged() {
updateSubscriptions(null);
}
};
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@@ -58,18 +69,42 @@ public class MobileSettingsActivity extends SettingsBaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSubscriptionManager = getSystemService(SubscriptionManager.class);
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
mPrevSubscriptionId = CollectionUtils.isEmpty(mSubscriptionInfos)
? SubscriptionManager.INVALID_SUBSCRIPTION_ID
: mSubscriptionInfos.get(0).getSubscriptionId();
setContentView(R.layout.mobile_settings_container);
mSubscriptionManager = getSystemService(SubscriptionManager.class);
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
mCurSubscriptionId = savedInstanceState != null
? savedInstanceState.getInt(KEY_CUR_SUBSCRIPTION_ID)
: null;
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
updateSubscriptions(savedInstanceState);
}
@Override
protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
saveInstanceState(outState);
}
@VisibleForTesting
void saveInstanceState(@NonNull Bundle outState) {
outState.putInt(KEY_CUR_SUBSCRIPTION_ID, mCurSubscriptionId);
}
@VisibleForTesting
void updateSubscriptions(Bundle savedInstanceState) {
//TODO(b/114749736): Sort it by phoneId
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
final int subId = CollectionUtils.isEmpty(mSubscriptionInfos)
? SubscriptionManager.INVALID_SUBSCRIPTION_ID
: mSubscriptionInfos.get(0).getSubscriptionId();
updateBottomNavigationView();
if (savedInstanceState == null) {
switchFragment(new MobileNetworkFragment(), mPrevSubscriptionId);
switchFragment(new MobileNetworkFragment(), subId);
}
}
@@ -89,24 +124,27 @@ public class MobileSettingsActivity extends SettingsBaseActivity {
}
navigation.setOnNavigationItemSelectedListener(item -> {
switchFragment(new MobileNetworkFragment(), item.getItemId());
mPrevSubscriptionId = item.getItemId();
return true;
});
}
}
@VisibleForTesting
void switchFragment(Fragment fragment, int subscriptionId) {
if (mCurSubscriptionId != null && subscriptionId == mCurSubscriptionId) {
return;
}
final FragmentManager fragmentManager = getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
final Bundle bundle = new Bundle();
bundle.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
final Fragment hideFragment = fragmentManager.findFragmentByTag(
buildFragmentTag(mPrevSubscriptionId));
if (hideFragment != null) {
fragmentTransaction.hide(hideFragment);
if (mCurSubscriptionId != null) {
final Fragment hideFragment = fragmentManager.findFragmentByTag(
buildFragmentTag(mCurSubscriptionId));
if (hideFragment != null) {
fragmentTransaction.hide(hideFragment);
}
}
Fragment showFragment = fragmentManager.findFragmentByTag(buildFragmentTag(subscriptionId));
@@ -118,6 +156,7 @@ public class MobileSettingsActivity extends SettingsBaseActivity {
fragmentTransaction.show(showFragment);
}
fragmentTransaction.commit();
mCurSubscriptionId = subscriptionId;
}
private String buildFragmentTag(int subscriptionId) {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Context;
import android.graphics.Color;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.app.ProgressDialog;
import android.content.Context;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.annotation.IntDef;
import android.telephony.AccessNetworkConstants.AccessNetworkType;

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2006 The Android Open Source Project
* 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.
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.app.ProgressDialog;
import android.content.Context;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.content.Context;
import android.os.AsyncTask;

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -26,7 +26,6 @@ import android.telephony.CarrierConfigManager;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
@@ -60,7 +59,6 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
mSubId = args.getInt(SUB_ID_KEY);
mCarrierConfigManager = new CarrierConfigManager(context);
//TODO(b/114749736): set target fragment in host fragment
Fragment fragment = getTargetFragment();
try {
mListener = (RoamingDialogListener) fragment;

View File

@@ -16,12 +16,15 @@
*/
package com.android.settings.search;
import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_NO;
import android.annotation.NonNull;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Toolbar;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.overlay.FeatureFactory;
@@ -53,15 +56,23 @@ public interface SearchFeatureProvider {
return "com.android.settings.intelligence";
}
/**
* Initializes the search toolbar.
*/
default void initSearchToolbar(Activity activity, View view) {
if (activity == null || view == null) {
default void initSearchToolbar(Activity activity, Toolbar toolbar) {
if (activity == null || toolbar == null) {
return;
}
view.setOnClickListener(tb -> {
// Please forgive me for what I am about to do.
//
// Need to make the navigation icon non-clickable so that the entire card is clickable
// and goes to the search UI. Also set the background to null so there's no ripple.
final View navView = toolbar.getNavigationView();
navView.setClickable(false);
navView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
navView.setBackground(null);
toolbar.setOnClickListener(tb -> {
final Intent intent = SEARCH_UI_INTENT;
intent.setPackage(getSettingsIntelligencePkgName());
final Context context = activity.getApplicationContext();

View File

@@ -42,7 +42,7 @@ import com.android.settings.bluetooth.BluetoothSliceBuilder;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.flashlight.FlashlightSliceBuilder;
import com.android.settings.location.LocationSliceBuilder;
import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.notification.ZenModeSliceBuilder;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.wifi.WifiSlice;

View File

@@ -19,7 +19,7 @@ package com.android.settings.slices;
import static com.android.settings.bluetooth.BluetoothSliceBuilder.ACTION_BLUETOOTH_SLICE_CHANGED;
import static com.android.settings.flashlight.FlashlightSliceBuilder
.ACTION_FLASHLIGHT_SLICE_CHANGED;
import static com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper
import static com.android.settings.network.telephony.Enhanced4gLteSliceHelper
.ACTION_ENHANCED_4G_LTE_CHANGED;
import static com.android.settings.notification.ZenModeSliceBuilder.ACTION_ZEN_MODE_SLICE_CHANGED;
import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CHANGED;

View File

@@ -2,7 +2,7 @@ package com.android.settings.slices;
import android.content.Context;
import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
/**

View File

@@ -2,7 +2,7 @@ package com.android.settings.slices;
import android.content.Context;
import com.android.settings.mobilenetwork.Enhanced4gLteSliceHelper;
import com.android.settings.network.telephony.Enhanced4gLteSliceHelper;
import com.android.settings.wifi.calling.WifiCallingSliceHelper;
import com.android.settingslib.utils.ThreadUtils;

View File

@@ -19,8 +19,6 @@ package com.android.settings.bluetooth;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import android.content.Intent;
@@ -56,7 +54,7 @@ public class BluetoothSliceBuilderTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -19,8 +19,6 @@ package com.android.settings.flashlight;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.provider.Settings;
@@ -50,7 +48,7 @@ public class FlashlightSliceBuilderTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -56,7 +56,7 @@ public class DataUsageSliceTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -57,7 +57,7 @@ public class DeviceInfoSliceTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -19,12 +19,10 @@ package com.android.settings.homepage.deviceinfo;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.res.Resources;
import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
@@ -56,7 +54,7 @@ public class StorageSliceTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -53,6 +53,18 @@ public class SliceContextualCardRendererTest {
mRenderer = new SliceContextualCardRenderer(mContext, mLifecycleOwner);
}
@Test
public void bindView_shouldSetScrollableToFalse() {
final String sliceUri = "content://com.android.settings.slices/action/flashlight";
RecyclerView.ViewHolder viewHolder = getSliceViewHolder();
mRenderer.bindView(viewHolder, buildContextualCard(sliceUri));
assertThat(
((SliceContextualCardRenderer.SliceViewHolder) viewHolder).sliceView.isScrollable
()).isFalse();
}
@Test
public void bindView_invalidScheme_sliceShouldBeNull() {
final String sliceUri = "contet://com.android.settings.slices/action/flashlight";

View File

@@ -2,8 +2,6 @@ package com.android.settings.location;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import androidx.core.graphics.drawable.IconCompat;
@@ -32,7 +30,7 @@ public class LocationSliceBuilderTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static android.app.slice.Slice.HINT_TITLE;
@@ -79,7 +79,7 @@ public class Enhanced4gLteSliceHelperTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mSlicesFeatureProvider = mFeatureFactory.getSlicesFeatureProvider();

View File

@@ -0,0 +1,149 @@
/*
* 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;
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
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.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.SwitchPreference;
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 MobileDataPreferenceControllerTest {
private static final int SUB_ID = 2;
@Mock
private FragmentManager mFragmentManager;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private TelephonyManager mInvalidTelephonyManager;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private SubscriptionInfo mSubscriptionInfo;
@Mock
private FragmentTransaction mFragmentTransaction;
private MobileDataPreferenceController mController;
private SwitchPreference mPreference;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
mPreference = new SwitchPreference(mContext);
mController = new MobileDataPreferenceController(mContext, "mobile_data");
mController.init(mFragmentManager, SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
}
@Test
public void getAvailabilityStatus_invalidSubscription_returnUnavailable() {
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
public void isDialogNeeded_disableSingleSim_returnTrue() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(1).when(mTelephonyManager).getSimCount();
assertThat(mController.isDialogNeeded()).isTrue();
assertThat(mController.mDialogType).isEqualTo(MobileDataDialogFragment.TYPE_DISABLE_DIALOG);
}
@Test
public void isDialogNeeded_enableNonDefaultSimInMultiSimMode_returnTrue() {
doReturn(false).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
doReturn(null).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(2).when(mTelephonyManager).getSimCount();
doReturn(1).when(mTelephonyManager).getNumberOfModemsWithSimultaneousDataConnections();
assertThat(mController.isDialogNeeded()).isTrue();
assertThat(mController.mDialogType).isEqualTo(
MobileDataDialogFragment.TYPE_MULTI_SIM_DIALOG);
}
@Test
public void handlePreferenceTreeClick_needDialog_showDialog() {
mController.mNeedDialog = true;
mController.handlePreferenceTreeClick(mPreference);
verify(mFragmentManager).beginTransaction();
}
@Test
public void onPreferenceChange_needDialog_doNothing() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(1).when(mTelephonyManager).getSimCount();
mController.onPreferenceChange(mPreference, true);
verify(mTelephonyManager, never()).setDataEnabled(true);
}
@Test
public void onPreferenceChange_notNeedDialog_update() {
doReturn(true).when(mTelephonyManager).isDataEnabled();
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getActiveSubscriptionInfo(SUB_ID);
doReturn(mSubscriptionInfo).when(mSubscriptionManager).getDefaultDataSubscriptionInfo();
doReturn(2).when(mTelephonyManager).getSimCount();
mController.onPreferenceChange(mPreference, true);
verify(mTelephonyManager).setDataEnabled(true);
}
}

View File

@@ -0,0 +1,145 @@
/*
* 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;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.nullable;
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.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.telecom.PhoneAccountHandle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
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;
import java.util.ArrayList;
import java.util.Arrays;
@RunWith(SettingsRobolectricTestRunner.class)
public class MobileNetworkUtilsTest {
private static final String PACKAGE_NAME = "com.android.app";
private static final int SUB_ID_1 = 1;
private static final int SUB_ID_2 = 2;
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private TelephonyManager mTelephonyManager2;
@Mock
private SubscriptionManager mSubscriptionManager;
@Mock
private SubscriptionInfo mSubscriptionInfo1;
@Mock
private SubscriptionInfo mSubscriptionInfo2;
@Mock
private PackageManager mPackageManager;
@Mock
private PhoneAccountHandle mPhoneAccountHandle;
@Mock
private ComponentName mComponentName;
@Mock
private ResolveInfo mResolveInfo;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID_1);
doReturn(mTelephonyManager2).when(mTelephonyManager).createForSubscriptionId(SUB_ID_2);
doReturn(mPackageManager).when(mContext).getPackageManager();
doReturn(mComponentName).when(mPhoneAccountHandle).getComponentName();
doReturn(PACKAGE_NAME).when(mComponentName).getPackageName();
doReturn(SUB_ID_1).when(mSubscriptionInfo1).getSubscriptionId();
doReturn(SUB_ID_2).when(mSubscriptionInfo2).getSubscriptionId();
doReturn(Arrays.asList(mSubscriptionInfo1, mSubscriptionInfo2)).when(
mSubscriptionManager).getActiveSubscriptionInfoList();
}
@Test
public void setMobileDataEnabled_setEnabled_enabled() {
MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_1, true, false);
verify(mTelephonyManager).setDataEnabled(true);
verify(mTelephonyManager2, never()).setDataEnabled(anyBoolean());
}
@Test
public void setMobileDataEnabled_setDisabled_disabled() {
MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_2, true, false);
verify(mTelephonyManager2).setDataEnabled(true);
verify(mTelephonyManager, never()).setDataEnabled(anyBoolean());
}
@Test
public void setMobileDataEnabled_disableOtherSubscriptions() {
MobileNetworkUtils.setMobileDataEnabled(mContext, SUB_ID_1, true, true);
verify(mTelephonyManager).setDataEnabled(true);
verify(mTelephonyManager2).setDataEnabled(false);
}
@Test
public void buildConfigureIntent_nullHandle_returnNull() {
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext, null)).isNull();
}
@Test
public void buildConfigureIntent_noActivityHandleIntent_returnNull() {
doReturn(new ArrayList<ResolveInfo>()).when(mPackageManager).queryIntentActivities(
nullable(Intent.class), anyInt());
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
mPhoneAccountHandle)).isNull();
}
@Test
public void buildConfigureIntent_hasActivityHandleIntent_returnIntent() {
doReturn(Arrays.asList(mResolveInfo)).when(mPackageManager).queryIntentActivities(
nullable(Intent.class), anyInt());
assertThat(MobileNetworkUtils.buildPhoneAccountConfigureIntent(mContext,
mPhoneAccountHandle)).isNotNull();
}
}

View File

@@ -14,9 +14,9 @@
* limitations under the License.
*/
package com.android.settings.mobilenetwork;
package com.android.settings.network.telephony;
import static com.android.settings.mobilenetwork.MobileSettingsActivity.MOBILE_SETTINGS_TAG;
import static com.android.settings.network.telephony.MobileSettingsActivity.MOBILE_SETTINGS_TAG;
import static com.google.common.truth.Truth.assertThat;
@@ -25,11 +25,16 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.view.Menu;
import android.view.View;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.android.internal.view.menu.ContextMenuBuilder;
import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
@@ -41,15 +46,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import java.util.ArrayList;
import java.util.List;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
@RunWith(SettingsRobolectricTestRunner.class)
public class MobileSettingsActivityTest {
@@ -120,7 +122,7 @@ public class MobileSettingsActivityTest {
@Test
public void switchFragment_hidePreviousFragment() {
mMobileSettingsActivity.mPrevSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.switchFragment(mShowFragment, CURRENT_SUB_ID);
@@ -129,7 +131,7 @@ public class MobileSettingsActivityTest {
@Test
public void switchFragment_fragmentExist_showItWithArguments() {
mMobileSettingsActivity.mPrevSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
mMobileSettingsActivity.switchFragment(mShowFragment, CURRENT_SUB_ID);
@@ -137,4 +139,17 @@ public class MobileSettingsActivityTest {
MobileSettingsActivity.KEY_SUBSCRIPTION_ID)).isEqualTo(CURRENT_SUB_ID);
verify(mFragmentTransaction).show(mShowFragment);
}
@Test
public void onSaveInstanceState_saveCurrentSubId() {
mMobileSettingsActivity = Robolectric.buildActivity(
MobileSettingsActivity.class).get();
mMobileSettingsActivity.mCurSubscriptionId = PREV_SUB_ID;
final Bundle bundle = new Bundle();
mMobileSettingsActivity.saveInstanceState(bundle);
assertThat(bundle.getInt(MobileSettingsActivity.KEY_CUR_SUBSCRIPTION_ID)).isEqualTo(
PREV_SUB_ID);
}
}

View File

@@ -20,8 +20,6 @@ import static android.app.slice.Slice.EXTRA_TOGGLE_STATE;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
@@ -55,7 +53,7 @@ public class ZenModeSliceBuilderTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -44,7 +44,7 @@ public class SearchFeatureProviderImplTest {
@Before
public void setUp() {
FakeFeatureFactory.setupForTest();
mActivity = Robolectric.buildActivity(Activity.class).create().visible().get();
mActivity = Robolectric.setupActivity(Activity.class);
mProvider = spy(new SearchFeatureProviderImpl());
}
@@ -54,6 +54,8 @@ public class SearchFeatureProviderImplTest {
// Should not crash.
final Toolbar toolbar = new Toolbar(mActivity);
// This ensures navigationView is created.
toolbar.setNavigationContentDescription("test");
mProvider.initSearchToolbar(mActivity, toolbar);
toolbar.performClick();

View File

@@ -79,7 +79,7 @@ public class SliceBuilderUtilsTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
mFeatureFactory = FakeFeatureFactory.setupForTest();
mLoggingArgumentCatpor = ArgumentCaptor.forClass(Pair.class);

View File

@@ -19,8 +19,6 @@ package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.WifiManager;
@@ -53,7 +51,7 @@ public class WifiSliceTest {
@Before
public void setUp() {
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
// Set-up specs for SliceMetadata.
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);

View File

@@ -86,7 +86,7 @@ public class WifiCallingSliceHelperTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mContext = RuntimeEnvironment.application;
//setup for SettingsSliceProvider tests
mProvider = spy(new SettingsSliceProvider());