Snap for 5616629 from d08b633e28 to qt-release

Change-Id: I407f23d152b3f2ab341b5ea0cf23c9107d3705e3
This commit is contained in:
android-build-team Robot
2019-05-30 03:13:17 +00:00
14 changed files with 241 additions and 446 deletions

View File

@@ -102,8 +102,6 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL" />
<protected-broadcast android:name="com.android.settings.DELETE_SIM_PROFILE_RESULT"/>
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
android:theme="@style/Theme.Settings"

View File

@@ -7335,7 +7335,7 @@
<string name="keywords_assist_gesture_launch">gesture</string>
<string name="keywords_face_unlock">face, unlock, auth, sign in</string>
<string name="keywords_imei_info">imei, meid, min, prl version, imei sv</string>
<string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid</string>
<string name="keywords_sim_status">network, mobile network state, service state, signal strength, mobile network type, roaming, iccid, eid</string>
<string name="keywords_model_and_hardware">serial number, hardware version</string>
<string name="keywords_android_version">android security patch level, baseband version, kernel version</string>
<!-- Search keywords for dark mode settings [CHAR LIMIT=NONE] -->
@@ -7901,6 +7901,9 @@
<!-- Configure Notifications: setting summary [CHAR LIMIT=200] -->
<string name="asst_capabilities_actions_replies_summary">Automatically show suggested actions &amp; replies</string>
<!-- Configure Notifications: setting title, whether the snooze menu is shown on notifications [CHAR LIMIT=80] -->
<string name="snooze_options_title">Allow notification snoozing</string>
<!-- Configure Notifications: setting title [CHAR LIMIT=80] -->
<string name="hide_silent_icons_title">Hide icons from gentle notifications</string>
@@ -8101,7 +8104,7 @@
<string name="notification_silence_title">Silent</string>
<!-- [CHAR LIMIT=100] Notification Importance title -->
<string name="notification_alert_title">Prioritized</string>
<string name="notification_alert_title">Alerting</string>
<!-- [CHAR LIMIT=40] Notification importance title. This setting controls how notifications in older apps may alert the user (eg, sound, visual, vibrate). -->
<string name="allow_interruption">Allow interruptions</string>
@@ -11216,11 +11219,11 @@
<string name="forget_passpoint_dialog_message">You may lose access to any remaining time or data. Check with your provider before removing.</string>
<!-- Keywords for Content Capture feature [CHAR_LIMIT=none] -->
<string name="keywords_content_capture">content capture, app content, app data</string>
<string name="keywords_content_capture">content capture, app content</string>
<!-- Title of the 'Content Capture' feature toggle in the Settings -> Privacy screen [CHAR LIMIT=none]-->
<string name="content_capture">Personalize using app data</string>
<string name="content_capture">App content</string>
<!-- Description of the 'Content Capture' feature toggle in the Settings -> Privacy screen [CHAR LIMIT=NONE]-->
<string name="content_capture_summary">Allow apps to send content to the Android system. Tap to learn more.</string>
<string name="content_capture_summary">Allow apps to send content to the Android system</string>
<!-- Title for the button to initiate a heap dump for the system server. [CHAR LIMIT=NONE] -->
<string name="capture_system_heap_dump_title">Capture system heap dump</string>

View File

@@ -79,6 +79,11 @@
android:order="15"
settings:initialExpandedChildrenCount="0">
<SwitchPreference
android:key="show_snooze_options"
android:title="@string/snooze_options_title"
settings:controller="com.android.settings.notification.SnoozeNotificationPreferenceController" />
<SwitchPreference
android:key="asst_capabilities_actions_replies"
android:title="@string/asst_capabilities_actions_replies_title"

View File

@@ -1,83 +0,0 @@
/*
* Copyright (C) 2019 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.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class DeleteSimProfileConfirmationDialog extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener {
public static final String TAG = "confirm_delete_sim";
public static final String KEY_SUBSCRIPTION_INFO = "subscription_info";
private SubscriptionInfo mInfo;
public static DeleteSimProfileConfirmationDialog newInstance(SubscriptionInfo info) {
final DeleteSimProfileConfirmationDialog dialog =
new DeleteSimProfileConfirmationDialog();
final Bundle args = new Bundle();
args.putParcelable(KEY_SUBSCRIPTION_INFO, info);
dialog.setArguments(args);
return dialog;
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
mInfo = getArguments().getParcelable(KEY_SUBSCRIPTION_INFO);
Context context = getContext();
final String message = context.getString(R.string.mobile_network_erase_sim_dialog_body,
mInfo.getCarrierName(), mInfo.getCarrierName());
return new AlertDialog.Builder(context)
.setTitle(R.string.mobile_network_erase_sim_dialog_title)
.setMessage(message)
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.mobile_network_erase_sim_dialog_ok, this)
.create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) {
beginDeletionWithProgress();
}
}
@VisibleForTesting
void beginDeletionWithProgress() {
final DeleteSimProfileProgressDialog progress =
DeleteSimProfileProgressDialog.newInstance(mInfo.getSubscriptionId());
progress.setTargetFragment(getTargetFragment(), 0);
progress.show(getFragmentManager(), DeleteSimProfileProgressDialog.TAG);
}
@Override
public int getMetricsCategory() {
return SettingsEnums.DIALOG_DELETE_SIM_CONFIRMATION;
}
}

View File

@@ -17,7 +17,9 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.content.Intent;
import android.telephony.SubscriptionInfo;
import android.telephony.euicc.EuiccManager;
import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
@@ -31,12 +33,13 @@ public class DeleteSimProfilePreferenceController extends BasePreferenceControll
private SubscriptionInfo mSubscriptionInfo;
private Fragment mParentFragment;
private int mRequestCode;
public DeleteSimProfilePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
public void init(int subscriptionId, Fragment parentFragment) {
public void init(int subscriptionId, Fragment parentFragment, int requestCode) {
mParentFragment = parentFragment;
for (SubscriptionInfo info : SubscriptionUtil.getAvailableSubscriptions(
@@ -46,6 +49,7 @@ public class DeleteSimProfilePreferenceController extends BasePreferenceControll
break;
}
}
mRequestCode = requestCode;
}
@Override
@@ -53,11 +57,10 @@ public class DeleteSimProfilePreferenceController extends BasePreferenceControll
super.displayPreference(screen);
final Preference pref = screen.findPreference(getPreferenceKey());
pref.setOnPreferenceClickListener(p -> {
final DeleteSimProfileConfirmationDialog dialogFragment =
DeleteSimProfileConfirmationDialog.newInstance(mSubscriptionInfo);
dialogFragment.setTargetFragment(mParentFragment, 0);
dialogFragment.show(mParentFragment.getFragmentManager(),
DeleteSimProfileConfirmationDialog.TAG);
final Intent intent = new Intent(EuiccManager.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED);
intent.putExtra(EuiccManager.EXTRA_SUBSCRIPTION_ID,
mSubscriptionInfo.getSubscriptionId());
mParentFragment.startActivityForResult(intent, mRequestCode);
return true;
});
}

View File

@@ -1,120 +0,0 @@
/*
* Copyright (C) 2019 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.Activity;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.app.settings.SettingsEnums;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.euicc.EuiccManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class DeleteSimProfileProgressDialog extends InstrumentedDialogFragment {
public static final String TAG = "delete_sim_progress";
// Note that this must be listed in AndroidManfiest.xml in a <protected-broadcast> tag
@VisibleForTesting
static final String PENDING_INTENT =
"com.android.settings.DELETE_SIM_PROFILE_RESULT";
private static final int PENDING_INTENT_REQUEST_CODE = 1;
private static final String KEY_SUBSCRIPTION_ID = "subscription_id";
@VisibleForTesting
static final String KEY_DELETE_STARTED = "delete_started";
private boolean mDeleteStarted;
private BroadcastReceiver mReceiver;
public static DeleteSimProfileProgressDialog newInstance(int subscriptionId) {
final DeleteSimProfileProgressDialog dialog = new DeleteSimProfileProgressDialog();
final Bundle args = new Bundle();
args.putInt(KEY_SUBSCRIPTION_ID, subscriptionId);
dialog.setArguments(args);
return dialog;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(KEY_DELETE_STARTED, mDeleteStarted);
}
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (savedInstanceState != null) {
mDeleteStarted = savedInstanceState.getBoolean(KEY_DELETE_STARTED, false);
}
final Context context = getContext();
final ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setMessage(
context.getString(R.string.mobile_network_erase_sim_dialog_progress));
mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
dismiss();
final Activity activity = getActivity();
if (activity != null && !activity.isFinishing()) {
activity.finish();
}
}
};
context.registerReceiver(mReceiver, new IntentFilter(PENDING_INTENT));
if (!mDeleteStarted) {
final PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
PENDING_INTENT_REQUEST_CODE, new Intent(PENDING_INTENT),
PendingIntent.FLAG_ONE_SHOT);
final EuiccManager euiccManager = context.getSystemService(EuiccManager.class);
final int subId = getArguments().getInt(KEY_SUBSCRIPTION_ID);
euiccManager.deleteSubscription(subId, pendingIntent);
mDeleteStarted = true;
}
return progressDialog;
}
@Override
public void onDismiss(@NonNull DialogInterface dialog) {
if (mReceiver != null) {
final Context context = getContext();
if (context != null) {
context.unregisterReceiver(mReceiver);
}
mReceiver = null;
}
}
@Override
public int getMetricsCategory() {
return SettingsEnums.DIALOG_DELETE_SIM_PROGRESS;
}
}

View File

@@ -61,6 +61,7 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
private static final String LOG_TAG = "NetworkSettings";
public static final int REQUEST_CODE_EXIT_ECM = 17;
public static final int REQUEST_CODE_DELETE_SUBSCRIPTION = 18;
@VisibleForTesting
static final String KEY_CLICKED_PREF = "key_clicked_pref";
@@ -138,7 +139,8 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
use(BillingCyclePreferenceController.class).init(mSubId);
use(MmsMessagePreferenceController.class).init(mSubId);
use(DisabledSubscriptionController.class).init(getLifecycle(), mSubId);
use(DeleteSimProfilePreferenceController.class).init(mSubId, this);
use(DeleteSimProfilePreferenceController.class).init(mSubId, this,
REQUEST_CODE_DELETE_SUBSCRIPTION);
}
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
@@ -226,6 +228,13 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {
}
break;
case REQUEST_CODE_DELETE_SUBSCRIPTION:
final Activity activity = getActivity();
if (activity != null && !activity.isFinishing()) {
activity.finish();
}
break;
default:
break;
}

View File

@@ -95,13 +95,9 @@ public class RenameMobileNetworkDialogFragment extends InstrumentedDialogFragmen
builder.setTitle(R.string.mobile_network_sim_name)
.setView(view)
.setPositiveButton(R.string.mobile_network_sim_name_rename, (dialog, which) -> {
SubscriptionInfo currentInfo = mSubscriptionManager.getActiveSubscriptionInfo(
mSubId);
String newName = mNameView.getText().toString();
if (currentInfo != null && !currentInfo.getDisplayName().equals(newName)) {
mSubscriptionManager.setDisplayName(newName, mSubId,
SubscriptionManager.NAME_SOURCE_USER_INPUT);
}
mSubscriptionManager.setDisplayName(newName, mSubId,
SubscriptionManager.NAME_SOURCE_USER_INPUT);
})
.setNegativeButton(android.R.string.cancel, null);
return builder.create();

View File

@@ -0,0 +1,56 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
import android.content.Context;
import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
import androidx.annotation.VisibleForTesting;
public class SnoozeNotificationPreferenceController extends TogglePreferenceController {
private static final String TAG = "SnoozeNotifPrefContr";
@VisibleForTesting
static final int ON = 1;
@VisibleForTesting
static final int OFF = 0;
public SnoozeNotificationPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public boolean isChecked() {
return Settings.Secure.getInt(mContext.getContentResolver(),
SHOW_NOTIFICATION_SNOOZE, OFF) == ON;
}
@Override
public boolean setChecked(boolean isChecked) {
return Settings.Secure.putInt(mContext.getContentResolver(),
SHOW_NOTIFICATION_SNOOZE, isChecked ? ON : OFF);
}
}

View File

@@ -1,79 +0,0 @@
/*
* Copyright (C) 2019 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 org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.telephony.SubscriptionInfo;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.androidx.fragment.FragmentController;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowAlertDialogCompat.class)
public class DeleteSimProfileConfirmationDialogTest {
@Mock
private SubscriptionInfo mSubscriptionInfo;
private DeleteSimProfileConfirmationDialog mDialogFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mDialogFragment = spy(DeleteSimProfileConfirmationDialog.newInstance(mSubscriptionInfo));
doNothing().when(mDialogFragment).beginDeletionWithProgress();
}
@Test
public void showDialog_dialogCancelled_deleteNotCalled() {
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
0 /* containerViewId */,
null /* bundle */);
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
verify(mDialogFragment, never()).beginDeletionWithProgress();
}
@Test
public void showDialog_dialogOk_deleteWasCalled() {
FragmentController.setupFragment(mDialogFragment, FragmentActivity.class,
0 /* containerViewId */,
null /* bundle */);
final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
verify(mDialogFragment).beginDeletionWithProgress();
}
}

View File

@@ -18,11 +18,15 @@ package com.android.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.euicc.EuiccManager;
import androidx.fragment.app.Fragment;
@@ -35,6 +39,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@@ -46,12 +51,12 @@ import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
public class DeleteSimProfilePreferenceControllerTest {
private static final String PREF_KEY = "delete_profile_key";
private static final int REQUEST_CODE = 4321;
private static final int SUB_ID = 1234;
private static final int OTHER_ID = 5678;
@Mock
private Fragment mFragment;
@Mock
private SubscriptionInfo mSubscriptionInfo;
@Mock
@@ -85,27 +90,42 @@ public class DeleteSimProfilePreferenceControllerTest {
@Test
public void getAvailabilityStatus_noSubs_notAvailable() {
SubscriptionUtil.setAvailableSubscriptionsForTesting(new ArrayList<>());
mController.init(SUB_ID, mFragment);
mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_physicalSim_notAvailable() {
when(mSubscriptionInfo.isEmbedded()).thenReturn(false);
mController.init(SUB_ID, mFragment);
mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_unknownSim_notAvailable() {
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(OTHER_ID);
mController.init(SUB_ID, mFragment);
mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void getAvailabilityStatus_knownEsim_isAvailable() {
mController.init(SUB_ID, mFragment);
mController.init(SUB_ID, mFragment, REQUEST_CODE);
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void onPreferenceClick_startsIntent() {
mController.init(SUB_ID, mFragment, REQUEST_CODE);
mController.displayPreference(mScreen);
mPreference.performClick();
final ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mFragment).startActivityForResult(intentCaptor.capture(), eq(REQUEST_CODE));
final Intent intent = intentCaptor.getValue();
assertThat(intent.getAction()).isEqualTo(
EuiccManager.ACTION_DELETE_SUBSCRIPTION_PRIVILEGED);
assertThat(intent.getIntExtra(EuiccManager.EXTRA_SUBSCRIPTION_ID,
SubscriptionManager.INVALID_SUBSCRIPTION_ID)).isEqualTo(SUB_ID);
}
}

View File

@@ -1,139 +0,0 @@
/*
* Copyright (C) 2019 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.network.telephony.DeleteSimProfileProgressDialog.KEY_DELETE_STARTED;
import static com.android.settings.network.telephony.DeleteSimProfileProgressDialog.PENDING_INTENT;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.notNull;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.Dialog;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.euicc.EuiccManager;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowAlertDialogCompat.class)
public class DeleteSimProfileProgressDialogTest {
private static final int SUB_ID = 111;
@Mock
private FragmentActivity mActivity;
@Mock
private Fragment mTargetFragment;
@Mock
private EuiccManager mEuiccManager;
private Context mContext;
private DeleteSimProfileProgressDialog mDialogFragment;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
when(mContext.getSystemService(EuiccManager.class)).thenReturn(mEuiccManager);
mDialogFragment = spy(DeleteSimProfileProgressDialog.newInstance(SUB_ID));
when(mDialogFragment.getContext()).thenReturn(mContext);
when(mDialogFragment.getTargetFragment()).thenReturn(mTargetFragment);
when(mDialogFragment.getActivity()).thenReturn(mActivity);
}
@Test
public void onCreateDialog_firstShowing_deleteStartedAndRecordedInOutState() {
mDialogFragment.onCreateDialog(null);
verify(mEuiccManager).deleteSubscription(eq(SUB_ID), notNull());
final Bundle outState = new Bundle();
mDialogFragment.onSaveInstanceState(outState);
assertThat(outState.containsKey(KEY_DELETE_STARTED)).isTrue();
assertThat(outState.getBoolean(KEY_DELETE_STARTED)).isTrue();
}
@Test
public void showDialog_secondShowing_deleteNotStarted() {
final Bundle inState = new Bundle();
inState.putBoolean(KEY_DELETE_STARTED, true);
mDialogFragment.onCreateDialog(inState);
verify(mEuiccManager, never()).deleteSubscription(anyInt(), any());
final Bundle outState = new Bundle();
mDialogFragment.onSaveInstanceState(outState);
assertThat(outState.containsKey(KEY_DELETE_STARTED)).isTrue();
assertThat(outState.getBoolean(KEY_DELETE_STARTED)).isTrue();
}
@Test
public void showDialog_pendingIntentReceiverFired_activityFinished() {
mDialogFragment.onCreateDialog(null);
final ArgumentCaptor<PendingIntent> intentCaptor = ArgumentCaptor.forClass(
PendingIntent.class);
verify(mEuiccManager).deleteSubscription(eq(SUB_ID), intentCaptor.capture());
assertThat(intentCaptor.getValue()).isNotNull();
final ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(
BroadcastReceiver.class);
verify(mContext).registerReceiver(receiverCaptor.capture(), any(IntentFilter.class));
doNothing().when(mDialogFragment).dismiss();
receiverCaptor.getValue().onReceive(mContext, new Intent(PENDING_INTENT));
verify(mDialogFragment).dismiss();
verify(mActivity).finish();
}
@Test
public void onDismiss_receiverUnregistered() {
Dialog dialog = mDialogFragment.onCreateDialog(null);
final ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(
BroadcastReceiver.class);
verify(mContext).registerReceiver(receiverCaptor.capture(), any(IntentFilter.class));
mDialogFragment.onDismiss(dialog);
verify(mContext).unregisterReceiver(eq(receiverCaptor.getValue()));
}
}

View File

@@ -16,11 +16,14 @@
package com.android.settings.network.telephony;
import static com.android.settings.network.telephony.MobileNetworkSettings.REQUEST_CODE_DELETE_SUBSCRIPTION;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.usage.NetworkStatsManager;
@@ -80,6 +83,7 @@ public class MobileNetworkSettingsTest {
args.putInt(Settings.EXTRA_SUB_ID, subscriptionId);
mFragment.setArguments(args);
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.isFinishing()).thenReturn(false);
when(mActivity.getSystemService(NetworkPolicyManager.class)).thenReturn(
mNetworkPolicyManager);
}
@@ -118,4 +122,17 @@ public class MobileNetworkSettingsTest {
.count())
.isEqualTo(1);
}
@Test
public void onActivityResult_noActivity_noCrash() {
when(mFragment.getActivity()).thenReturn(null);
// this should not crash
mFragment.onActivityResult(REQUEST_CODE_DELETE_SUBSCRIPTION, 0, null);
}
@Test
public void onActivityResult_deleteSubscription_activityFinishes() {
mFragment.onActivityResult(REQUEST_CODE_DELETE_SUBSCRIPTION, 0, null);
verify(mActivity).finish();
}
}

View File

@@ -0,0 +1,109 @@
/*
* Copyright (C) 2019 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.notification;
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;
import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
import android.provider.Settings;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.TwoStatePreference;
@RunWith(RobolectricTestRunner.class)
public class SnoozeNotificationPreferenceControllerTest {
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private Context mContext;
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private PreferenceScreen mScreen;
private SnoozeNotificationPreferenceController mController;
private Preference mPreference;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mController = new SnoozeNotificationPreferenceController(mContext,
"key");
mPreference = new Preference(RuntimeEnvironment.application);
mPreference.setKey(mController.getPreferenceKey());
when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
@Test
public void display_configIsTrue_shouldDisplay() {
mController.displayPreference(mScreen);
assertThat(mPreference.isVisible()).isTrue();
}
@Test
public void isChecked_settingIsOff_shouldReturnFalse() {
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, OFF);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_settingIsOn_shouldReturnTrue() {
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, ON);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void setChecked_setFalse_disablesSetting() {
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, ON);
mController.setChecked(false);
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
SHOW_NOTIFICATION_SNOOZE, -1);
assertThat(updatedValue).isEqualTo(OFF);
}
@Test
public void setChecked_setTrue_enablesSetting() {
Settings.Secure.putInt(mContext.getContentResolver(), SHOW_NOTIFICATION_SNOOZE, OFF);
mController.setChecked(true);
int updatedValue = Settings.Secure.getInt(mContext.getContentResolver(),
SHOW_NOTIFICATION_SNOOZE, -1);
assertThat(updatedValue).isEqualTo(ON);
}
}