diff --git a/res/layout/dialog_sim_status.xml b/res/layout/dialog_sim_status.xml index b9abb15598b..80abc1ed0b0 100644 --- a/res/layout/dialog_sim_status.xml +++ b/res/layout/dialog_sim_status.xml @@ -156,15 +156,6 @@ android:layout_height="wrap_content" android:text="@string/device_info_not_available"/> - - - - - - - - - - - - diff --git a/src/com/android/settings/TrustedCredentialsDialogBuilder.java b/src/com/android/settings/TrustedCredentialsDialogBuilder.java index 363560e7fc9..9a739915bc0 100644 --- a/src/com/android/settings/TrustedCredentialsDialogBuilder.java +++ b/src/com/android/settings/TrustedCredentialsDialogBuilder.java @@ -309,6 +309,8 @@ class TrustedCredentialsDialogBuilder extends AlertDialog.Builder { LinearLayout certLayout = new LinearLayout(mActivity); certLayout.setOrientation(LinearLayout.VERTICAL); + // Prevent content overlapping with spinner + certLayout.setClipChildren(true); certLayout.addView(spinner); for (int i = 0; i < views.size(); ++i) { View certificateView = views.get(i); diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java index 4cebbef295d..a8c43fb3e10 100644 --- a/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java +++ b/src/com/android/settings/bluetooth/BluetoothDeviceDetailsFragment.java @@ -312,7 +312,8 @@ public class BluetoothDeviceDetailsFragment extends RestrictedDashboardFragment mCachedDevice, lifecycle)); controllers.add(new BluetoothDetailsMacAddressController(context, this, mCachedDevice, lifecycle)); - controllers.add(new StylusDevicesController(context, mInputDevice, lifecycle)); + controllers.add(new StylusDevicesController(context, mInputDevice, mCachedDevice, + lifecycle)); controllers.add(new BluetoothDetailsRelatedToolsController(context, this, mCachedDevice, lifecycle)); controllers.add(new BluetoothDetailsPairOtherController(context, this, mCachedDevice, diff --git a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java index bf2fdda88ff..024d6f569c3 100644 --- a/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java +++ b/src/com/android/settings/connecteddevice/stylus/StylusDevicesController.java @@ -17,12 +17,14 @@ package com.android.settings.connecteddevice.stylus; import android.app.role.RoleManager; +import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.provider.Settings; import android.provider.Settings.Secure; +import android.text.TextUtils; import android.util.Log; import android.view.InputDevice; @@ -34,6 +36,8 @@ import androidx.preference.PreferenceScreen; import androidx.preference.SwitchPreference; import com.android.settings.R; +import com.android.settingslib.bluetooth.BluetoothUtils; +import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.core.lifecycle.LifecycleObserver; @@ -61,18 +65,23 @@ public class StylusDevicesController extends AbstractPreferenceController implem @Nullable private final InputDevice mInputDevice; + @Nullable + private final CachedBluetoothDevice mCachedBluetoothDevice; + @VisibleForTesting PreferenceCategory mPreferencesContainer; - public StylusDevicesController(Context context, InputDevice inputDevice, Lifecycle lifecycle) { + public StylusDevicesController(Context context, InputDevice inputDevice, + CachedBluetoothDevice cachedBluetoothDevice, Lifecycle lifecycle) { super(context); mInputDevice = inputDevice; + mCachedBluetoothDevice = cachedBluetoothDevice; lifecycle.addObserver(this); } @Override public boolean isAvailable() { - return mInputDevice != null && mInputDevice.supportsSource(InputDevice.SOURCE_STYLUS); + return isDeviceStylus(mInputDevice, mCachedBluetoothDevice); } @Nullable @@ -179,13 +188,11 @@ public class StylusDevicesController extends AbstractPreferenceController implem private void refresh() { if (!isAvailable()) return; - if (mInputDevice.getBluetoothAddress() != null) { - Preference notesPref = mPreferencesContainer.findPreference(KEY_DEFAULT_NOTES); - if (notesPref == null) { - notesPref = createDefaultNotesPreference(); - if (notesPref != null) { - mPreferencesContainer.addPreference(notesPref); - } + Preference notesPref = mPreferencesContainer.findPreference(KEY_DEFAULT_NOTES); + if (notesPref == null) { + notesPref = createDefaultNotesPreference(); + if (notesPref != null) { + mPreferencesContainer.addPreference(notesPref); } } @@ -201,4 +208,32 @@ public class StylusDevicesController extends AbstractPreferenceController implem mPreferencesContainer.addPreference(createButtonPressPreference()); } } + + /** + * Identifies whether a device is a stylus using the associated {@link InputDevice} or + * {@link CachedBluetoothDevice}. + * + * InputDevices are only available when the device is USI or Bluetooth-connected, whereas + * CachedBluetoothDevices are available for Bluetooth devices when connected or paired, + * so to handle all cases, both are needed. + * + * @param inputDevice The associated input device of the stylus + * @param cachedBluetoothDevice The associated bluetooth device of the stylus + */ + public static boolean isDeviceStylus(@Nullable InputDevice inputDevice, + @Nullable CachedBluetoothDevice cachedBluetoothDevice) { + if (inputDevice != null && inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)) { + return true; + } + + if (cachedBluetoothDevice != null) { + BluetoothDevice bluetoothDevice = cachedBluetoothDevice.getDevice(); + String deviceType = BluetoothUtils.getStringMetaData(bluetoothDevice, + BluetoothDevice.METADATA_DEVICE_TYPE); + return TextUtils.equals(deviceType, BluetoothDevice.DEVICE_TYPE_STYLUS); + } + + return false; + } + } diff --git a/src/com/android/settings/connecteddevice/stylus/StylusUsiDetailsFragment.java b/src/com/android/settings/connecteddevice/stylus/StylusUsiDetailsFragment.java index 4691a5b79e3..9aaf15d3e7e 100644 --- a/src/com/android/settings/connecteddevice/stylus/StylusUsiDetailsFragment.java +++ b/src/com/android/settings/connecteddevice/stylus/StylusUsiDetailsFragment.java @@ -77,7 +77,7 @@ public class StylusUsiDetailsFragment extends DashboardFragment { if (mInputDevice != null) { Lifecycle lifecycle = getSettingsLifecycle(); controllers.add(new StylusUsiHeaderController(context, mInputDevice)); - controllers.add(new StylusDevicesController(context, mInputDevice, lifecycle)); + controllers.add(new StylusDevicesController(context, mInputDevice, null, lifecycle)); } return controllers; } diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java index 855cd122f41..e6f7a0ebc75 100644 --- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java +++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java @@ -22,7 +22,6 @@ import android.annotation.Nullable; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.IntentFilter; import android.content.ServiceConnection; @@ -47,7 +46,6 @@ import android.telephony.SubscriptionManager.OnSubscriptionsChangedListener; import android.telephony.TelephonyCallback; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; -import android.telephony.UiccCardInfo; import android.telephony.euicc.EuiccManager; import android.telephony.ims.ImsException; import android.telephony.ims.ImsMmTelManager; @@ -64,17 +62,13 @@ import com.android.settings.R; import com.android.settingslib.DeviceInfoUtils; import com.android.settingslib.Utils; import com.android.settingslib.core.lifecycle.Lifecycle; -import com.android.settingslib.utils.ThreadUtils; import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicReference; /** * Controller for Sim Status information within the About Phone Settings page. */ -public class SimStatusDialogController implements LifecycleObserver, - DialogInterface.OnShowListener { +public class SimStatusDialogController implements LifecycleObserver { private final static String TAG = "SimStatusDialogCtrl"; @@ -105,12 +99,6 @@ public class SimStatusDialogController implements LifecycleObserver, @VisibleForTesting final static int ICCID_INFO_VALUE_ID = R.id.icc_id_value; @VisibleForTesting - final static int EID_INFO_LABEL_ID = R.id.esim_id_label; - @VisibleForTesting - final static int EID_INFO_VALUE_ID = R.id.esim_id_value; - @VisibleForTesting - final static int EID_INFO_QRCODE_ID = R.id.esim_id_qrcode; - @VisibleForTesting final static int IMS_REGISTRATION_STATE_LABEL_ID = R.id.ims_reg_state_label; @VisibleForTesting final static int IMS_REGISTRATION_STATE_VALUE_ID = R.id.ims_reg_state_value; @@ -162,7 +150,6 @@ public class SimStatusDialogController implements LifecycleObserver, private boolean mShowLatestAreaInfo; private boolean mIsRegisteredListener = false; - private AtomicReference mEid = null; private final BroadcastReceiver mAreaInfoReceiver = new BroadcastReceiver() { @Override @@ -239,8 +226,6 @@ public class SimStatusDialogController implements LifecycleObserver, } public void initialize() { - requestForUpdateEid(); - if (mSubscriptionInfo == null) { return; } @@ -268,19 +253,6 @@ public class SimStatusDialogController implements LifecycleObserver, updateImsRegistrationState(); } - /** - * Callback when dialog end of show(). - */ - public void onShow(DialogInterface dialog) { - if (mEid != null) { - String eidText = mEid.get(); - if (eidText != null) { - // Present QR code after the completion of layout - mDialog.setQrCode(EID_INFO_QRCODE_ID, eidText); - } - } - } - /** * Deinitialization works */ @@ -633,71 +605,6 @@ public class SimStatusDialogController implements LifecycleObserver, } } - @VisibleForTesting - protected void requestForUpdateEid() { - ThreadUtils.postOnBackgroundThread(() -> { - mEid = getEid(mSlotIndex); - ThreadUtils.postOnMainThread(() -> updateEid(mEid)); - }); - } - - @VisibleForTesting - public AtomicReference getEid(int slotIndex) { - boolean shouldHaveEid = false; - String eid = null; - if (getTelephonyManager().getActiveModemCount() > MAX_PHONE_COUNT_SINGLE_SIM) { - // Get EID per-SIM in multi-SIM mode - final Map mapping = mTelephonyManager - .getLogicalToPhysicalSlotMapping(); - final int pSlotId = mapping.getOrDefault(slotIndex, - SubscriptionManager.INVALID_SIM_SLOT_INDEX); - - if (pSlotId != SubscriptionManager.INVALID_SIM_SLOT_INDEX) { - final List infos = getTelephonyManager().getUiccCardsInfo(); - - for (UiccCardInfo info : infos) { - if (info.getPhysicalSlotIndex() == pSlotId) { - if (info.isEuicc()) { - shouldHaveEid = true; - eid = info.getEid(); - if (TextUtils.isEmpty(eid)) { - eid = mEuiccManager.createForCardId(info.getCardId()).getEid(); - } - } - break; - } - } - } - } else if (mEuiccManager.isEnabled()) { - // Get EID of default eSIM in single-SIM mode - shouldHaveEid = true; - eid = mEuiccManager.getEid(); - } - if ((!shouldHaveEid) && (eid == null)) { - return null; - } - return new AtomicReference(eid); - } - - @VisibleForTesting - protected void updateEid(AtomicReference eid) { - boolean removeQrCode = true; - if (eid == null) { - mDialog.removeSettingFromScreen(EID_INFO_LABEL_ID); - mDialog.removeSettingFromScreen(EID_INFO_VALUE_ID); - mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID); - } else { - String eidText = eid.get(); - if (eidText != null) { - mDialog.setText(EID_INFO_VALUE_ID, eidText); - removeQrCode = (eidText == ""); - } - } - if (removeQrCode) { - mDialog.removeSettingFromScreen(EID_INFO_QRCODE_ID); - } - } - private boolean isImsRegistrationStateShowUp() { if (mSubscriptionInfo == null) { return false; diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java index 3bd9b343b2d..4105db1037e 100644 --- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java +++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogFragment.java @@ -19,14 +19,11 @@ package com.android.settings.deviceinfo.simstatus; import android.app.Dialog; import android.app.settings.SettingsEnums; import android.os.Bundle; -import android.graphics.Bitmap; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; -import android.widget.ImageView; import android.widget.TextView; -import android.util.Log; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; @@ -35,7 +32,6 @@ import androidx.fragment.app.FragmentManager; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.deviceinfo.PhoneNumberUtil; -import com.android.settingslib.qrcode.QrCodeGenerator; import java.util.Arrays; import java.util.stream.IntStream; @@ -84,7 +80,6 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { Dialog dlg = builder.setView(mRootView).create(); dlg.getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); - dlg.setOnShowListener(mController); return dlg; } @@ -107,8 +102,7 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { **/ private static final int[] sViewIdsInDigitFormat = IntStream .of(SimStatusDialogController.ICCID_INFO_VALUE_ID, - SimStatusDialogController.PHONE_NUMBER_VALUE_ID, - SimStatusDialogController.EID_INFO_VALUE_ID) + SimStatusDialogController.PHONE_NUMBER_VALUE_ID) .sorted().toArray(); public void setText(int viewId, CharSequence text) { @@ -128,19 +122,4 @@ public class SimStatusDialogFragment extends InstrumentedDialogFragment { textView.setText(text); textView.setTextIsSelectable(enableCopy); } - - public void setQrCode(int viewId, String qrcodeText) { - ImageView qrCodeView = (ImageView) mRootView.findViewById(viewId); - - Bitmap qrCodeBitmap = null; - try { - qrCodeBitmap = QrCodeGenerator.encodeQrCode(qrcodeText, qrCodeView.getWidth()); - } catch (Exception exception) { - Log.w(TAG, "Error when presenting QR code in + " + qrCodeView, exception); - } - if (qrCodeBitmap == null) { - return; - } - qrCodeView.setImageBitmap(qrCodeBitmap); - } } diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java index 4dcdc0cc111..61e0fb1b110 100644 --- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java +++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtils.java @@ -44,9 +44,7 @@ import com.android.settings.fuelgauge.batterytip.tips.UnrestrictAppTip; import java.util.ArrayList; import java.util.List; -/** - * Utility class for {@link BatteryTip} - */ +/** Utility class for {@link BatteryTip} */ public class BatteryTipUtils { private static final int REQUEST_CODE = 0; @@ -85,6 +83,7 @@ public class BatteryTipUtils { /** * Get a corresponding action based on {@code batteryTip} + * * @param batteryTip used to detect which action to choose * @param settingsActivity used to populate {@link BatteryTipAction} * @param fragment used to populate {@link BatteryTipAction} diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTip.java deleted file mode 100644 index 6701314fa82..00000000000 --- a/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTip.java +++ /dev/null @@ -1,104 +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.fuelgauge.batterytip.tips; - -import android.app.settings.SettingsEnums; -import android.content.Context; -import android.os.Parcel; - -import com.android.settings.R; -import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; - -/** - * Tip to show early warning if battery couldn't make to usual charging time - */ -public class EarlyWarningTip extends BatteryTip { - private boolean mPowerSaveModeOn; - - public EarlyWarningTip(@StateType int state, boolean powerSaveModeOn) { - super(TipType.BATTERY_SAVER, state, false /* showDialog */); - mPowerSaveModeOn = powerSaveModeOn; - } - - public EarlyWarningTip(Parcel in) { - super(in); - mPowerSaveModeOn = in.readBoolean(); - } - - @Override - public CharSequence getTitle(Context context) { - return context.getString( - mState = R.string.battery_tip_early_heads_up_title); - } - - @Override - public CharSequence getSummary(Context context) { - return context.getString( - mState = R.string.battery_tip_early_heads_up_summary); - } - - @Override - public int getIconId() { - return mState = R.drawable.ic_battery_status_bad_24dp; - } - - @Override - public int getIconTintColorId() { - return mState = R.color.battery_bad_color_light; - } - - @Override - public void updateState(BatteryTip tip) { - final EarlyWarningTip earlyWarningTip = (EarlyWarningTip) tip; - if (earlyWarningTip.mState == StateType.NEW) { - // Display it if there is early warning - mState = StateType.NEW; - } else if (earlyWarningTip.mPowerSaveModeOn) { - // If powerSaveMode is really on, dismiss it. - mState = StateType.INVISIBLE; - } else { - mState = earlyWarningTip.getState(); - } - mPowerSaveModeOn = earlyWarningTip.mPowerSaveModeOn; - } - - @Override - public void log(Context context, MetricsFeatureProvider metricsFeatureProvider) { - metricsFeatureProvider.action(context, SettingsEnums.ACTION_EARLY_WARNING_TIP, - mState); - } - - @Override - public void writeToParcel(Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeBoolean(mPowerSaveModeOn); - } - - public boolean isPowerSaveModeOn() { - return mPowerSaveModeOn; - } - - public static final Creator CREATOR = new Creator() { - public BatteryTip createFromParcel(Parcel in) { - return new EarlyWarningTip(in); - } - - public BatteryTip[] newArray(int size) { - return new EarlyWarningTip[size]; - } - }; -} diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java index 930a8113cff..79d78e27a1f 100644 --- a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java +++ b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java @@ -24,18 +24,19 @@ import android.os.Parcelable; import com.android.settings.R; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; -/** - * Tip to show current battery level is low or remaining time is less than a certain period - */ -public class LowBatteryTip extends EarlyWarningTip { +/** Tip to show current battery level is low */ +public class LowBatteryTip extends BatteryTip { + + private boolean mPowerSaveModeOn; public LowBatteryTip(@StateType int state, boolean powerSaveModeOn) { - super(state, powerSaveModeOn); - mType = TipType.LOW_BATTERY; + super(TipType.LOW_BATTERY, state, false /* showDialog */); + mPowerSaveModeOn = powerSaveModeOn; } public LowBatteryTip(Parcel in) { super(in); + mPowerSaveModeOn = in.readBoolean(); } @Override @@ -48,9 +49,20 @@ public class LowBatteryTip extends EarlyWarningTip { return context.getString(R.string.battery_tip_low_battery_summary); } + @Override + public int getIconId() { + return mState = R.drawable.ic_battery_status_bad_24dp; + } + + @Override + public int getIconTintColorId() { + return mState = R.color.battery_bad_color_light; + } + @Override public void writeToParcel(Parcel dest, int flags) { super.writeToParcel(dest, flags); + dest.writeBoolean(mPowerSaveModeOn); } @Override @@ -59,6 +71,17 @@ public class LowBatteryTip extends EarlyWarningTip { mState); } + @Override + public void updateState(BatteryTip tip) { + final LowBatteryTip lowBatteryTip = (LowBatteryTip) tip; + mState = lowBatteryTip.mPowerSaveModeOn + ? StateType.INVISIBLE : lowBatteryTip.getState(); + } + + boolean isPowerSaveModeOn() { + return mPowerSaveModeOn; + } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public BatteryTip createFromParcel(Parcel in) { return new LowBatteryTip(in); diff --git a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java index b1ca911eecf..e93b4727e1d 100644 --- a/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java +++ b/tests/robotests/src/com/android/settings/connecteddevice/stylus/StylusDevicesControllerTest.java @@ -26,6 +26,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.app.role.RoleManager; +import android.bluetooth.BluetoothDevice; import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; @@ -44,6 +45,7 @@ import androidx.preference.SwitchPreference; import androidx.test.core.app.ApplicationProvider; import com.android.settings.R; +import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.core.lifecycle.Lifecycle; import org.junit.Before; @@ -76,6 +78,10 @@ public class StylusDevicesControllerTest { private RoleManager mRm; @Mock private Lifecycle mLifecycle; + @Mock + private CachedBluetoothDevice mCachedBluetoothDevice; + @Mock + private BluetoothDevice mBluetoothDevice; @Before @@ -101,24 +107,94 @@ public class StylusDevicesControllerTest { any(PackageManager.ApplicationInfoFlags.class))).thenReturn(new ApplicationInfo()); when(mPm.getApplicationLabel(any(ApplicationInfo.class))).thenReturn(NOTES_APP_LABEL); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + mInputDevice = spy(new InputDevice.Builder() .setId(1) .setSources(InputDevice.SOURCE_STYLUS) .build()); when(mInputDevice.getBluetoothAddress()).thenReturn("SOME:ADDRESS"); - mController = new StylusDevicesController(mContext, mInputDevice, mLifecycle); + mController = new StylusDevicesController(mContext, mInputDevice, null, mLifecycle); } @Test - public void noInputDevice_noPreference() { + public void isDeviceStylus_noDevices_false() { + assertThat(StylusDevicesController.isDeviceStylus(null, null)).isFalse(); + } + + @Test + public void isDeviceStylus_nonStylusInputDevice_false() { + InputDevice inputDevice = new InputDevice.Builder() + .setSources(InputDevice.SOURCE_DPAD) + .build(); + + assertThat(StylusDevicesController.isDeviceStylus(inputDevice, null)).isFalse(); + } + + @Test + public void isDeviceStylus_stylusInputDevice_true() { + InputDevice inputDevice = new InputDevice.Builder() + .setSources(InputDevice.SOURCE_STYLUS) + .build(); + + assertThat(StylusDevicesController.isDeviceStylus(inputDevice, null)).isTrue(); + } + + @Test + public void isDeviceStylus_nonStylusBluetoothDevice_false() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( + BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); + + assertThat(StylusDevicesController.isDeviceStylus(null, mCachedBluetoothDevice)).isFalse(); + } + + @Test + public void isDeviceStylus_stylusBluetoothDevice_true() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( + BluetoothDevice.DEVICE_TYPE_STYLUS.getBytes()); + when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice); + + assertThat(StylusDevicesController.isDeviceStylus(null, mCachedBluetoothDevice)).isTrue(); + } + + @Test + public void noInputDevice_noBluetoothDevice_noPreference() { StylusDevicesController controller = new StylusDevicesController( - mContext, null, mLifecycle + mContext, null, null, mLifecycle ); + showScreen(controller); + assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(0); } + @Test + public void noInputDevice_nonStylusBluetoothDevice_noPreference() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( + BluetoothDevice.DEVICE_TYPE_WATCH.getBytes()); + StylusDevicesController controller = new StylusDevicesController( + mContext, null, mCachedBluetoothDevice, mLifecycle + ); + + showScreen(controller); + + assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(0); + } + + @Test + public void noInputDevice_stylusBluetoothDevice_showsPreference() { + when(mBluetoothDevice.getMetadata(BluetoothDevice.METADATA_DEVICE_TYPE)).thenReturn( + BluetoothDevice.DEVICE_TYPE_STYLUS.getBytes()); + StylusDevicesController controller = new StylusDevicesController( + mContext, null, mCachedBluetoothDevice, mLifecycle + ); + + showScreen(controller); + + assertThat(mPreferenceContainer.getPreferenceCount()).isEqualTo(3); + } + @Test public void btStylusInputDevice_showsAllPreferences() { showScreen(mController); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java index 3bb33c62cdd..3312e16277c 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipUtilsTest.java @@ -28,7 +28,6 @@ import com.android.settings.fuelgauge.batterytip.actions.OpenRestrictAppFragment import com.android.settings.fuelgauge.batterytip.actions.RestrictAppAction; import com.android.settings.fuelgauge.batterytip.tips.BatteryDefenderTip; import com.android.settings.fuelgauge.batterytip.tips.BatteryTip; -import com.android.settings.fuelgauge.batterytip.tips.EarlyWarningTip; import com.android.settings.fuelgauge.batterytip.tips.LowBatteryTip; import com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip; import com.android.settings.testutils.FakeFeatureFactory; @@ -51,7 +50,6 @@ public class BatteryTipUtilsTest { @Mock private InstrumentedPreferenceFragment mFragment; private RestrictAppTip mRestrictAppTip; - private EarlyWarningTip mEarlyWarningTip; private LowBatteryTip mLowBatteryTip; private BatteryDefenderTip mBatteryDefenderTip; @@ -63,8 +61,6 @@ public class BatteryTipUtilsTest { when(mSettingsActivity.getApplicationContext()).thenReturn(RuntimeEnvironment.application); when(mFragment.getContext()).thenReturn(RuntimeEnvironment.application); mRestrictAppTip = spy(new RestrictAppTip(BatteryTip.StateType.NEW, new ArrayList<>())); - mEarlyWarningTip = spy( - new EarlyWarningTip(BatteryTip.StateType.NEW, true /* powerSaveModeOn */)); mLowBatteryTip = spy( new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */)); mBatteryDefenderTip = spy(new BatteryDefenderTip(BatteryTip.StateType.NEW)); @@ -86,14 +82,6 @@ public class BatteryTipUtilsTest { mFragment)).isInstanceOf(OpenRestrictAppFragmentAction.class); } - @Test - public void testGetActionForBatteryTip_typeEarlyWarningStateNew_returnActionOpen() { - when(mEarlyWarningTip.getState()).thenReturn(BatteryTip.StateType.NEW); - - assertThat(BatteryTipUtils.getActionForBatteryTip(mEarlyWarningTip, mSettingsActivity, - mFragment)).isInstanceOf(OpenBatterySaverAction.class); - } - @Test public void testGetActionForBatteryTip_typeLowBatteryStateNew_returnActionOpen() { when(mLowBatteryTip.getState()).thenReturn(BatteryTip.StateType.NEW); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTipTest.java deleted file mode 100644 index aeea10fc0b3..00000000000 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/EarlyWarningTipTest.java +++ /dev/null @@ -1,127 +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.fuelgauge.batterytip.tips; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.verify; - -import android.content.Context; -import android.os.Parcel; - -import com.android.internal.logging.nano.MetricsProto; -import com.android.settings.R; -import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -@RunWith(RobolectricTestRunner.class) -public class EarlyWarningTipTest { - - @Mock - private MetricsFeatureProvider mMetricsFeatureProvider; - private Context mContext; - private EarlyWarningTip mEarlyWarningTip; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - - mContext = RuntimeEnvironment.application; - mEarlyWarningTip = - new EarlyWarningTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */); - } - - @Test - public void testParcelable() { - Parcel parcel = Parcel.obtain(); - mEarlyWarningTip.writeToParcel(parcel, mEarlyWarningTip.describeContents()); - parcel.setDataPosition(0); - - final EarlyWarningTip parcelTip = new EarlyWarningTip(parcel); - - assertThat(parcelTip.isPowerSaveModeOn()).isFalse(); - } - - @Test - public void testInfo_stateNew_displayPowerModeInfo() { - final EarlyWarningTip tip = - new EarlyWarningTip(BatteryTip.StateType.NEW, false /* powerModeOn */); - - assertThat(tip.getTitle(mContext)).isEqualTo("Turn on Battery Saver"); - assertThat(tip.getSummary(mContext)).isEqualTo("Battery may run out earlier than usual"); - assertThat(tip.getIconId()).isEqualTo(R.drawable.ic_battery_status_bad_24dp); - assertThat(tip.getIconTintColorId()).isEqualTo(R.color.battery_bad_color_light); - } - - @Test - public void testUpdate_powerModeTurnedOn_typeBecomeInvisible() { - final EarlyWarningTip nextTip = - new EarlyWarningTip(BatteryTip.StateType.INVISIBLE, true /* powerModeOn */); - - mEarlyWarningTip.updateState(nextTip); - - assertThat(mEarlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE); - } - - @Test - public void testUpdate_devicePluggedIn_typeBecomeInvisible() { - final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE, - false /* powerModeOn */); - - mEarlyWarningTip.updateState(nextTip); - - assertThat(mEarlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE); - } - - @Test - public void testUpdate_turnOnLowPowerModeExplicitly_typeStillInvisible() { - final EarlyWarningTip earlyWarningTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE, - false /* powerModeOn */); - final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE, - true /* powerModeOn */); - - earlyWarningTip.updateState(nextTip); - - assertThat(earlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE); - } - - @Test - public void testUpdate_turnOffLowPowerModeExplicitly_typeBecomeInvisible() { - final EarlyWarningTip earlyWarningTip = new EarlyWarningTip(BatteryTip.StateType.HANDLED, - true /* powerModeOn */); - final EarlyWarningTip nextTip = new EarlyWarningTip(BatteryTip.StateType.INVISIBLE, - false /* powerModeOn */); - - earlyWarningTip.updateState(nextTip); - - assertThat(earlyWarningTip.getState()).isEqualTo(BatteryTip.StateType.INVISIBLE); - } - - @Test - public void testLog() { - mEarlyWarningTip.log(mContext, mMetricsFeatureProvider); - - verify(mMetricsFeatureProvider).action(mContext, - MetricsProto.MetricsEvent.ACTION_EARLY_WARNING_TIP, BatteryTip.StateType.NEW); - } -} diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTipTest.java index ff96b5b07a5..108a1dde45f 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTipTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTipTest.java @@ -23,6 +23,7 @@ import android.content.Context; import android.os.Parcel; import com.android.internal.logging.nano.MetricsProto; +import com.android.settings.R; import com.android.settingslib.core.instrumentation.MetricsFeatureProvider; import org.junit.Before; @@ -36,8 +37,6 @@ import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) public class LowBatteryTipTest { - private static final CharSequence SUMMARY = "Turn on Battery Saver to extend battery life"; - @Mock private MetricsFeatureProvider mMetricsFeatureProvider; private Context mContext; @@ -46,7 +45,6 @@ public class LowBatteryTipTest { @Before public void setUp() { MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; mLowBatteryTip = new LowBatteryTip(BatteryTip.StateType.NEW, false /* powerSaveModeOn */); } @@ -60,21 +58,30 @@ public class LowBatteryTipTest { final LowBatteryTip parcelTip = new LowBatteryTip(parcel); assertThat(parcelTip.isPowerSaveModeOn()).isFalse(); - assertThat(parcelTip.getSummary(mContext)).isEqualTo(SUMMARY); + assertThat(parcelTip.getSummary(mContext)).isEqualTo( + mContext.getString(R.string.battery_tip_low_battery_summary)); } @Test - public void getSummary_tipNew_showTitle() { + public void updateState_stateNew_showExpectedInformation() { mLowBatteryTip.mState = BatteryTip.StateType.NEW; - assertThat(mLowBatteryTip.getTitle(mContext)).isEqualTo("Battery level low"); + assertThat(mLowBatteryTip.getTitle(mContext)).isEqualTo( + mContext.getString(R.string.battery_tip_low_battery_title)); + assertThat(mLowBatteryTip.getSummary(mContext)).isEqualTo( + mContext.getString(R.string.battery_tip_low_battery_summary)); + assertThat(mLowBatteryTip.getIconId()).isEqualTo(R.drawable.ic_battery_status_bad_24dp); + assertThat(mLowBatteryTip.getIconTintColorId()).isEqualTo(R.color.battery_bad_color_light); } @Test - public void getSummary_tipNew_showSummary() { - mLowBatteryTip.mState = BatteryTip.StateType.NEW; + public void updateState_powerSaveModeOn_notShowTipItem() { + final LowBatteryTip tip = new LowBatteryTip( + BatteryTip.StateType.NEW, true /* powerSaveModeOn */); - assertThat(mLowBatteryTip.getSummary(mContext)).isEqualTo(SUMMARY); + tip.updateState(tip); + + assertThat(tip.mState).isEqualTo(BatteryTip.StateType.INVISIBLE); } @Test diff --git a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java index 428c575e4a9..8c24cbb1d2e 100644 --- a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java +++ b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java @@ -18,8 +18,6 @@ package com.android.settings.deviceinfo.simstatus; import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.CELL_DATA_NETWORK_TYPE_VALUE_ID; import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.CELL_VOICE_NETWORK_TYPE_VALUE_ID; -import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.EID_INFO_LABEL_ID; -import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.EID_INFO_VALUE_ID; import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ICCID_INFO_LABEL_ID; import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.ICCID_INFO_VALUE_ID; import static com.android.settings.deviceinfo.simstatus.SimStatusDialogController.IMS_REGISTRATION_STATE_LABEL_ID; @@ -115,12 +113,8 @@ public class SimStatusDialogControllerTest { private LifecycleOwner mLifecycleOwner; private Lifecycle mLifecycle; private AtomicBoolean mEuiccEnabled; - private AtomicReference mEid; private AtomicInteger mUpdatePhoneNumberCount; - private static final String TEST_EID_FROM_CARD = "11111111111111111111111111111111"; - private static final String TEST_EID_FROM_MANAGER = "22222222222222222222222222222222"; - private static final int MAX_PHONE_COUNT_DUAL_SIM = 2; @Before @@ -149,21 +143,12 @@ public class SimStatusDialogControllerTest { mUpdatePhoneNumberCount = new AtomicInteger(); mEuiccEnabled = new AtomicBoolean(false); - mEid = new AtomicReference(""); mController = new SimStatusDialogController(mDialog, mLifecycle, 0 /* phone id */) { @Override public TelephonyManager getTelephonyManager() { return mTelephonyManager; } - @Override - protected void requestForUpdateEid() {} - - @Override - public AtomicReference getEid(int slotIndex) { - return mEuiccEnabled.get() ? mEid : null; - } - @Override public void updatePhoneNumber() { super.updatePhoneNumber(); @@ -205,7 +190,6 @@ public class SimStatusDialogControllerTest { doReturn(carrierName).when(mSubscriptionInfo).getCarrierName(); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(NETWORK_PROVIDER_VALUE_ID, carrierName); } @@ -213,7 +197,6 @@ public class SimStatusDialogControllerTest { @Test public void initialize_shouldUpdatePhoneNumber() { mController.initialize(); - mController.updateEid(mController.getEid(0)); assertTrue(mUpdatePhoneNumberCount.get() > 0); } @@ -223,7 +206,6 @@ public class SimStatusDialogControllerTest { when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).removeSettingFromScreen(OPERATOR_INFO_LABEL_ID); verify(mDialog).removeSettingFromScreen(OPERATOR_INFO_VALUE_ID); @@ -234,7 +216,6 @@ public class SimStatusDialogControllerTest { when(mServiceState.getState()).thenReturn(ServiceState.STATE_IN_SERVICE); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String inServiceText = ResourcesUtils.getResourcesString( mContext, "radioInfo_service_in"); @@ -246,7 +227,6 @@ public class SimStatusDialogControllerTest { when(mServiceState.getState()).thenReturn(ServiceState.STATE_POWER_OFF); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String offServiceText = ResourcesUtils.getResourcesString( mContext, "radioInfo_service_off"); @@ -261,7 +241,6 @@ public class SimStatusDialogControllerTest { ServiceState.STATE_OUT_OF_SERVICE); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String offServiceText = ResourcesUtils.getResourcesString( mContext, "radioInfo_service_out"); @@ -275,7 +254,6 @@ public class SimStatusDialogControllerTest { when(mServiceState.getDataRegistrationState()).thenReturn(ServiceState.STATE_IN_SERVICE); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String inServiceText = ResourcesUtils.getResourcesString( mContext, "radioInfo_service_in"); @@ -291,7 +269,6 @@ public class SimStatusDialogControllerTest { setupCellSignalStrength_lteWcdma(lteDbm, lteAsu, wcdmaDbm, wcdmaAsu); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String signalStrengthString = ResourcesUtils.getResourcesString( mContext, "sim_signal_strength", lteDbm, lteAsu); @@ -307,7 +284,6 @@ public class SimStatusDialogControllerTest { setupCellSignalStrength_lteCdma(lteDbm, lteAsu, cdmaDbm, cdmaAsu); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String signalStrengthString = ResourcesUtils.getResourcesString( mContext, "sim_signal_strength", lteDbm, lteAsu); @@ -324,7 +300,6 @@ public class SimStatusDialogControllerTest { setupCellSignalStrength_lteOnly(lteDbm, lteAsu); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String signalStrengthString = ResourcesUtils.getResourcesString( mContext, "sim_signal_strength", lteDbm, lteAsu); @@ -337,7 +312,6 @@ public class SimStatusDialogControllerTest { TelephonyManager.NETWORK_TYPE_EDGE); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(CELL_VOICE_NETWORK_TYPE_VALUE_ID, SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE)); @@ -349,7 +323,6 @@ public class SimStatusDialogControllerTest { TelephonyManager.NETWORK_TYPE_EDGE); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(CELL_DATA_NETWORK_TYPE_VALUE_ID, SimStatusDialogController.getNetworkTypeName(TelephonyManager.NETWORK_TYPE_EDGE)); @@ -360,7 +333,6 @@ public class SimStatusDialogControllerTest { when(mServiceState.getRoaming()).thenReturn(true); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String roamingOnString = ResourcesUtils.getResourcesString( mContext, "radioInfo_roaming_in"); @@ -372,7 +344,6 @@ public class SimStatusDialogControllerTest { when(mServiceState.getRoaming()).thenReturn(false); mController.initialize(); - mController.updateEid(mController.getEid(0)); final String roamingOffString = ResourcesUtils.getResourcesString( mContext, "radioInfo_roaming_not"); @@ -385,7 +356,6 @@ public class SimStatusDialogControllerTest { CarrierConfigManager.KEY_SHOW_ICCID_IN_SIM_STATUS_BOOL, false); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).removeSettingFromScreen(ICCID_INFO_LABEL_ID); verify(mDialog).removeSettingFromScreen(ICCID_INFO_VALUE_ID); @@ -397,7 +367,6 @@ public class SimStatusDialogControllerTest { CarrierConfigManager.KEY_SHOW_SIGNAL_STRENGTH_IN_SIM_STATUS_BOOL, false); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_LABEL_ID); verify(mDialog, times(2)).removeSettingFromScreen(SIGNAL_STRENGTH_VALUE_ID); @@ -409,7 +378,6 @@ public class SimStatusDialogControllerTest { when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(null); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog, times(2)).setText(eq(SIGNAL_STRENGTH_VALUE_ID), any()); verify(mDialog).removeSettingFromScreen(ICCID_INFO_LABEL_ID); @@ -423,403 +391,10 @@ public class SimStatusDialogControllerTest { doReturn(iccid).when(mTelephonyManager).getSimSerialNumber(); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(ICCID_INFO_VALUE_ID, iccid); } - @Test - public void initialize_updateEid_shouldNotSetEid() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo1 = new UiccCardInfo( - false, // isEuicc - 0, // cardId - null, // eid - 0, // slotIndex - true, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo1); - UiccCardInfo uiccCardInfo2 = new UiccCardInfo( - true, // isEuicc - 1, // cardId - null, // eid (unavailable) - 1, // slotIndex - false, // isRemovable - false, - Collections.singletonList( - new UiccPortInfo( - null, // iccId - 1, // portIdx - 1, // logicalSlotIdx - true // isActive - ) - ) - ); - uiccCardInfos.add(uiccCardInfo2); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 1); - slotMapping.put(1, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(null); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Keep 'Not available' if neither the card nor the associated manager can provide EID. - verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any()); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldSetEidFromCard() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo1 = new UiccCardInfo( - true, // isEuicc - 0, // cardId - TEST_EID_FROM_CARD, // eid - 0, // slotIndex - false, // isRemovable - false, - Collections.singletonList(new UiccPortInfo( - null, // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ))); - uiccCardInfos.add(uiccCardInfo1); - UiccCardInfo uiccCardInfo2 = new UiccCardInfo( - false, // isEuicc - 1, // cardId - null, // eid - 1, // slotIndex - true, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 1, // portIdx - 1, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo2); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - slotMapping.put(1, 1); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(TEST_EID_FROM_CARD); - when(mEuiccManager.createForCardId(0)).thenReturn(mEuiccManager); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Set EID retrieved from the card. - verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_CARD); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldSetEidFromManager() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo1 = new UiccCardInfo( - false, // isEuicc - 0, // cardId - null, // eid - 0, // slotIndex - true, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 1, // portIdx - 1, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo1); - UiccCardInfo uiccCardInfo2 = new UiccCardInfo( - true, // isEuicc - 1, // cardId - null, // eid (unavailable) - 1, // slotIndex - false, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - null, // iccId - 1, // portIdx - 1, // logicalSlotIdx - true // isActive - ) - ) - ); - uiccCardInfos.add(uiccCardInfo2); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 1); - slotMapping.put(1, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(TEST_EID_FROM_MANAGER); - when(mEuiccManager.createForCardId(0)).thenThrow( - new RuntimeException("Unexpected card ID was specified")); - when(mEuiccManager.createForCardId(1)).thenReturn(mEuiccManager); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Set EID retrieved from the manager associated with the card which cannot provide EID. - verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_MANAGER); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - @Ignore - public void initialize_updateEid_shouldRemoveEid() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_DUAL_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo1 = new UiccCardInfo( - false, // isEuicc - 0, // cardId - null, // eid - 0, // slotIndex - true, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo1); - UiccCardInfo uiccCardInfo2 = new UiccCardInfo( - true, // isEuicc - 1, // cardId - TEST_EID_FROM_CARD, // eid - 1, // slotIndex - false, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - null, // iccId - 1, // portIdx - 1, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo2); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - slotMapping.put(1, 1); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(null); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Remove EID if the card is not eUICC. - verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any()); - verify(mDialog).removeSettingFromScreen(eq(EID_INFO_LABEL_ID)); - verify(mDialog).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldNotSetEidInSingleSimMode() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo = new UiccCardInfo( - true, // isEuicc - 0, // cardId - TEST_EID_FROM_CARD, // eid (not used) - 0, // slotIndex - false, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - null, // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(null); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Keep 'Not available' if the default eUICC manager cannot provide EID in Single SIM mode. - verify(mDialog, never()).setText(eq(EID_INFO_VALUE_ID), any()); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldSetEidInSingleSimModeWithEnabledEuicc() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo = new UiccCardInfo( - true, // isEuicc (eUICC slot is selected) - 0, // cardId - TEST_EID_FROM_CARD, // eid (not used) - 0, // slotIndex - false, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - null, // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ) - ) - ); - uiccCardInfos.add(uiccCardInfo); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(TEST_EID_FROM_MANAGER); - when(mEuiccManager.createForCardId(anyInt())).thenThrow( - new RuntimeException("EID shall be retrieved from the default eUICC manager")); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Set EID retrieved from the default eUICC manager in Single SIM mode. - verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_MANAGER); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldSetEidInSingleSimModeWithDisabledEuicc() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo = new UiccCardInfo( - false, // isEuicc (eUICC slot is not selected) - 0, // cardId - null, // eid - 0, // slotIndex - true, // isRemovable - false, // isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - - ) - )); - uiccCardInfos.add(uiccCardInfo); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(true); - mEuiccEnabled.set(true); - mEid.set(TEST_EID_FROM_MANAGER); - when(mEuiccManager.createForCardId(anyInt())).thenThrow( - new RuntimeException("EID shall be retrieved from the default eUICC manager")); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Set EID retrieved from the default eUICC manager in Single SIM mode. - verify(mDialog).setText(EID_INFO_VALUE_ID, TEST_EID_FROM_MANAGER); - verify(mDialog, never()).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - - @Test - public void initialize_updateEid_shouldRemoveEidInSingleSimMode() { - when(mTelephonyManager.getActiveModemCount()).thenReturn(MAX_PHONE_COUNT_SINGLE_SIM); - - ArrayList uiccCardInfos = new ArrayList<>(); - UiccCardInfo uiccCardInfo = new UiccCardInfo( - false, // isEuicc - 0, // cardId - null, // eid - 0, // slotIndex - true, // isRemovable - false, //isMultipleEnabledProfileSupported - Collections.singletonList( - new UiccPortInfo( - "123451234567890", // iccId - 0, // portIdx - 0, // logicalSlotIdx - true // isActive - ) - )); - uiccCardInfos.add(uiccCardInfo); - when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos); - - Map slotMapping = new HashMap<>(); - slotMapping.put(0, 0); - when(mTelephonyManager.getLogicalToPhysicalSlotMapping()).thenReturn(slotMapping); - - when(mEuiccManager.isEnabled()).thenReturn(false); - mEuiccEnabled.set(false); - mEid.set(null); - - mController.initialize(); - mController.updateEid(mController.getEid(0)); - - // Remove EID if the default eUICC manager indicates that eSIM is not enabled. - verify(mDialog).removeSettingFromScreen(eq(EID_INFO_LABEL_ID)); - verify(mDialog).removeSettingFromScreen(eq(EID_INFO_VALUE_ID)); - } - @Test @Ignore public void initialize_imsRegistered_shouldSetImsRegistrationStateSummaryToRegisterd() { @@ -828,7 +403,6 @@ public class SimStatusDialogControllerTest { when(mTelephonyManager.isImsRegistered(anyInt())).thenReturn(true); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(IMS_REGISTRATION_STATE_VALUE_ID, mContext.getString(R.string.ims_reg_status_registered)); @@ -842,7 +416,6 @@ public class SimStatusDialogControllerTest { when(mTelephonyManager.isImsRegistered(anyInt())).thenReturn(false); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).setText(IMS_REGISTRATION_STATE_VALUE_ID, mContext.getString(R.string.ims_reg_status_not_registered)); @@ -855,7 +428,6 @@ public class SimStatusDialogControllerTest { CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL, true); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog, never()).removeSettingFromScreen(IMS_REGISTRATION_STATE_VALUE_ID); } @@ -867,7 +439,6 @@ public class SimStatusDialogControllerTest { CarrierConfigManager.KEY_SHOW_IMS_REGISTRATION_STATUS_BOOL, false); mController.initialize(); - mController.updateEid(mController.getEid(0)); verify(mDialog).removeSettingFromScreen(IMS_REGISTRATION_STATE_LABEL_ID); verify(mDialog).removeSettingFromScreen(IMS_REGISTRATION_STATE_VALUE_ID); @@ -878,7 +449,6 @@ public class SimStatusDialogControllerTest { doReturn(null).when(mTelephonyManager).getSignalStrength(); // we should not crash when running the following line mController.initialize(); - mController.updateEid(mController.getEid(0)); } private void setupCellSignalStrength_lteWcdma(int lteDbm, int lteAsu, int wcdmaDbm,