Snap for 8462561 from c4801433d9 to tm-release

Change-Id: Ifbd0c731f9ff1b446907c1e86c263d1810f832e2
This commit is contained in:
Android Build Coastguard Worker
2022-04-16 03:09:05 +00:00
23 changed files with 1244 additions and 1195 deletions

View File

@@ -34,7 +34,6 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingEnd="4dp"
android:singleLine="true"
android:textAlignment="viewStart"
style="@style/PreferenceCategoryTitleTextStyle"/>

View File

@@ -13,78 +13,26 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<TabHost
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:visibility="gone"/>
<LinearLayout
android:id="@+id/content"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/system_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:id="@+id/system_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:visibility="gone" />
<LinearLayout
android:id="@+id/system_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:animateLayoutChanges="true">
</LinearLayout>
</FrameLayout>
<FrameLayout
android:id="@+id/user_tab"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:id="@+id/user_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:visibility="gone" />
<LinearLayout
android:id="@+id/user_content"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:animateLayoutChanges="true">
</LinearLayout>
</FrameLayout>
</FrameLayout>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
</LinearLayout>
</TabHost>
</FrameLayout>

View File

@@ -26,28 +26,25 @@
settings:searchable="false"/>
<PreferenceCategory
android:key="dream_main_category">
<PreferenceCategory
android:title="@string/dream_picker_category">
<com.android.settingslib.widget.LayoutPreference
android:key="dream_picker"
android:selectable="false"
android:layout="@layout/dream_picker_layout"
settings:controller="com.android.settings.dream.DreamPickerController"/>
</PreferenceCategory>
android:title="@string/dream_picker_category">
<com.android.settingslib.widget.LayoutPreference
android:key="dream_picker"
android:selectable="false"
android:layout="@layout/dream_picker_layout"
settings:controller="com.android.settings.dream.DreamPickerController"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/dream_more_settings_category">
<SwitchPreference
android:key="dream_complications_toggle"
android:title="@string/dream_complications_toggle_title"
android:summary="@string/dream_complications_toggle_summary"
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
<Preference
android:key="when_to_start"
android:title="@string/screensaver_settings_when_to_dream"
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
</PreferenceCategory>
<PreferenceCategory
android:title="@string/dream_more_settings_category">
<SwitchPreference
android:key="dream_complications_toggle"
android:title="@string/dream_complications_toggle_title"
android:summary="@string/dream_complications_toggle_summary"
settings:controller="com.android.settings.dream.DreamComplicationPreferenceController"/>
<Preference
android:key="when_to_start"
android:title="@string/screensaver_settings_when_to_dream"
android:fragment="com.android.settings.dream.WhenToDreamPicker"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -34,7 +34,7 @@ import android.widget.Spinner;
import androidx.appcompat.app.AlertDialog;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.TrustedCredentialsSettings.CertHolder;
import com.android.settings.TrustedCredentialsFragment.CertHolder;
import com.android.settingslib.RestrictedLockUtils;
import java.security.cert.X509Certificate;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -132,8 +132,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
mShortcutPreference.setTitle(getShortcutTitle());
updateShortcutTitle(mShortcutPreference);
getPreferenceScreen().addPreference(mShortcutPreference);
mTouchExplorationStateChangeListener = isTouchExplorationEnabled -> {
@@ -192,13 +192,11 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
final Dialog dialog;
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
final CharSequence dialogTitle = getPrefContext().getString(
R.string.accessibility_shortcut_title, getLabelName());
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? AccessibilityDialogUtils.DialogType.EDIT_SHORTCUT_GENERIC_SUW :
AccessibilityDialogUtils.DialogType.EDIT_SHORTCUT_GENERIC;
dialog = AccessibilityDialogUtils.showEditShortcutDialog(
getPrefContext(), dialogType, dialogTitle,
getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(dialog);
return dialog;
@@ -213,9 +211,8 @@ public abstract class AccessibilityShortcutPreferenceFragment extends DashboardF
}
}
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
final CharSequence title = getString(R.string.accessibility_shortcut_title, getLabelName());
shortcutPreference.setTitle(title);
protected CharSequence getShortcutTitle() {
return getString(R.string.accessibility_shortcut_title, getLabelName());
}
@Override

View File

@@ -75,8 +75,8 @@ public class ToggleColorInversionPreferenceFragment extends ToggleFeaturePrefere
}
@Override
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
shortcutPreference.setTitle(R.string.accessibility_display_inversion_shortcut_title);
protected CharSequence getShortcutTitle() {
return getText(R.string.accessibility_display_inversion_shortcut_title);
}
@Override

View File

@@ -185,8 +185,8 @@ public final class ToggleDaltonizerPreferenceFragment extends ToggleFeaturePrefe
}
@Override
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
shortcutPreference.setTitle(R.string.accessibility_daltonizer_shortcut_title);
protected CharSequence getShortcutTitle() {
return getText(R.string.accessibility_daltonizer_shortcut_title);
}
@Override

View File

@@ -271,12 +271,10 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
public Dialog onCreateDialog(int dialogId) {
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
final CharSequence dialogTitle = getPrefContext().getString(
R.string.accessibility_shortcut_title, mPackageName);
final int dialogType = WizardManagerHelper.isAnySetupWizard(getIntent())
? DialogType.EDIT_SHORTCUT_GENERIC_SUW : DialogType.EDIT_SHORTCUT_GENERIC;
mDialog = AccessibilityDialogUtils.showEditShortcutDialog(
getPrefContext(), dialogType, dialogTitle,
getPrefContext(), dialogType, getShortcutTitle(),
this::callOnAlertDialogCheckboxClicked);
setupEditShortcutDialog(mDialog);
return mDialog;
@@ -341,9 +339,8 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
switchPreference.setTitle(title);
}
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
final CharSequence title = getString(R.string.accessibility_shortcut_title, mPackageName);
shortcutPreference.setTitle(title);
protected CharSequence getShortcutTitle() {
return getString(R.string.accessibility_shortcut_title, mPackageName);
}
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
@@ -516,8 +513,7 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
mShortcutPreference.setPersistent(false);
mShortcutPreference.setKey(getShortcutPreferenceKey());
mShortcutPreference.setOnClickCallback(this);
updateShortcutTitle(mShortcutPreference);
mShortcutPreference.setTitle(getShortcutTitle());
final PreferenceCategory generalCategory = findPreference(KEY_GENERAL_CATEGORY);
generalCategory.addPreference(mShortcutPreference);

View File

@@ -168,8 +168,8 @@ public class ToggleReduceBrightColorsPreferenceFragment extends ToggleFeaturePre
}
@Override
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
shortcutPreference.setTitle(R.string.reduce_bright_colors_shortcut_title);
protected CharSequence getShortcutTitle() {
return getText(R.string.reduce_bright_colors_shortcut_title);
}
@Override

View File

@@ -479,8 +479,8 @@ public class ToggleScreenMagnificationPreferenceFragment extends
}
@Override
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
shortcutPreference.setTitle(R.string.accessibility_screen_magnification_shortcut_title);
protected CharSequence getShortcutTitle() {
return getText(R.string.accessibility_screen_magnification_shortcut_title);
}
@Override

View File

@@ -92,7 +92,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
mProfilesContainer = (PreferenceCategory)screen.findPreference(getPreferenceKey());
mProfilesContainer.setLayoutResource(R.layout.preference_bluetooth_profile_category);
mIsLeContactSharingEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, false);
SettingsUIDeviceConfig.BT_LE_AUDIO_CONTACT_SHARING_ENABLED, true);
// Call refresh here even though it will get called later in onResume, to avoid the
// list of switches appearing to "pop" into the page.
refresh();
@@ -515,4 +515,4 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
public String getPreferenceKey() {
return KEY_PROFILES_GROUP;
}
}
}

View File

@@ -105,13 +105,6 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
icon.setBounds(0, 0, iconSize, iconSize);
mTitleView.setCompoundDrawablesRelative(icon, null, null, null);
if (item.isActive()) {
mLastSelectedPos = position;
itemView.setSelected(true);
} else {
itemView.setSelected(false);
}
mCustomizeButton.setOnClickListener(v -> item.onCustomizeClicked());
mCustomizeButton.setVisibility(
item.allowCustomization() && mEnabled ? View.VISIBLE : View.GONE);
@@ -125,6 +118,15 @@ public class DreamAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
notifyItemChanged(position);
});
if (item.isActive()) {
mLastSelectedPos = position;
itemView.setSelected(true);
itemView.setClickable(false);
} else {
itemView.setSelected(false);
itemView.setClickable(true);
}
setEnabledStateOnViews(itemView, mEnabled);
}

View File

@@ -16,12 +16,9 @@
package com.android.settings.dream;
import static com.android.settings.dream.DreamMainSwitchPreferenceController.MAIN_SWITCH_PREF_KEY;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Switch;
import androidx.annotation.Nullable;
import androidx.preference.Preference;
@@ -35,8 +32,6 @@ import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.dream.DreamBackend;
import com.android.settingslib.dream.DreamBackend.DreamInfo;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.MainSwitchPreference;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
import java.util.List;
import java.util.stream.Collectors;
@@ -44,8 +39,7 @@ import java.util.stream.Collectors;
/**
* Controller for the dream picker where the user can select a screensaver.
*/
public class DreamPickerController extends BasePreferenceController implements
OnMainSwitchChangeListener {
public class DreamPickerController extends BasePreferenceController {
private final DreamBackend mBackend;
private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -92,10 +86,13 @@ public class DreamPickerController extends BasePreferenceController implements
new GridSpacingItemDecoration(mContext, R.dimen.dream_preference_card_padding));
recyclerView.setHasFixedSize(true);
recyclerView.setAdapter(mAdapter);
}
final Preference mainSwitchPref = screen.findPreference(MAIN_SWITCH_PREF_KEY);
if (mainSwitchPref instanceof MainSwitchPreference) {
((MainSwitchPreference) mainSwitchPref).addOnSwitchChangeListener(this);
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mAdapter != null) {
mAdapter.setEnabled(preference.isEnabled());
}
}
@@ -108,13 +105,6 @@ public class DreamPickerController extends BasePreferenceController implements
.orElse(null);
}
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
if (mAdapter != null) {
mAdapter.setEnabled(isChecked);
}
}
private class DreamItem implements IDreamItem {
DreamInfo mDreamInfo;

View File

@@ -32,7 +32,7 @@ import android.widget.Button;
import android.widget.Switch;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceCategory;
import androidx.preference.Preference;
import androidx.recyclerview.widget.RecyclerView;
import com.android.settings.R;
@@ -57,10 +57,7 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
static final String EITHER_CHARGING_OR_DOCKED = "either_charging_or_docked";
static final String NEVER_DREAM = "never";
private static final String MAIN_PREF_CATEGORY = "dream_main_category";
private MainSwitchPreference mMainSwitchPreference;
private PreferenceCategory mMainPrefCategory;
private Button mPreviewButton;
private RecyclerView mRecyclerView;
@@ -152,6 +149,22 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
return controllers;
}
private void setAllPreferencesEnabled(boolean isEnabled) {
getPreferenceControllers().forEach(controllers -> {
controllers.forEach(controller -> {
final String prefKey = controller.getPreferenceKey();
if (prefKey.equals(MAIN_SWITCH_PREF_KEY)) {
return;
}
final Preference pref = findPreference(prefKey);
if (pref != null) {
pref.setEnabled(isEnabled);
controller.updateState(pref);
}
});
});
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -163,10 +176,7 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
mMainSwitchPreference.addOnSwitchChangeListener(this);
}
mMainPrefCategory = findPreference(MAIN_PREF_CATEGORY);
if (mMainPrefCategory != null) {
mMainPrefCategory.setEnabled(dreamBackend.isEnabled());
}
setAllPreferencesEnabled(dreamBackend.isEnabled());
}
@Override
@@ -194,7 +204,7 @@ public class DreamSettings extends DashboardFragment implements OnMainSwitchChan
@Override
public void onSwitchChanged(Switch switchView, boolean isChecked) {
mMainPrefCategory.setEnabled(isChecked);
setAllPreferencesEnabled(isChecked);
mPreviewButton.setVisibility(isChecked ? View.VISIBLE : View.GONE);
updatePaddingForPreviewButton();
}

View File

@@ -625,8 +625,9 @@ public class BatteryEntry {
iconId = R.drawable.ic_settings_phone_idle;
break;
default:
name = DebugUtils.constantToString(BatteryConsumer.class, "POWER_COMPONENT_",
powerComponentId);
Log.w(TAG, "unknown attribute:" + DebugUtils.constantToString(
BatteryConsumer.class, "POWER_COMPONENT_", powerComponentId));
name = null;
iconId = R.drawable.ic_power_system;
break;
}

View File

@@ -27,7 +27,6 @@ import com.android.internal.accessibility.AccessibilityShortcutController;
import com.android.settings.R;
import com.android.settings.accessibility.AccessibilityShortcutPreferenceFragment;
import com.android.settings.accessibility.AccessibilityUtil.QuickSettingsTooltipType;
import com.android.settings.accessibility.ShortcutPreference;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.widget.IllustrationPreference;
import com.android.settingslib.widget.MainSwitchPreference;
@@ -88,8 +87,8 @@ public class OneHandedSettings extends AccessibilityShortcutPreferenceFragment {
}
@Override
protected void updateShortcutTitle(ShortcutPreference shortcutPreference) {
shortcutPreference.setTitle(R.string.one_handed_mode_shortcut_title);
protected CharSequence getShortcutTitle() {
return getText(R.string.one_handed_mode_shortcut_title);
}
@Override

View File

@@ -38,10 +38,8 @@ import com.android.settingslib.widget.LayoutPreference;
public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModePreferenceController
implements PreferenceControllerMixin {
private final String KEY = PREF_KEY_APP_HEADER;
private final PreferenceFragmentCompat mFragment;
private AutomaticZenRule mRule;
private String mId;
private EntityHeaderController mController;
public ZenAutomaticRuleHeaderPreferenceController(Context context,
@@ -52,7 +50,11 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
@Override
public String getPreferenceKey() {
return KEY;
return PREF_KEY_APP_HEADER;
}
void setRule(AutomaticZenRule rule) {
mRule = rule;
}
@Override
@@ -96,9 +98,4 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
return null;
}
protected void onResume(AutomaticZenRule rule, String id) {
mRule = rule;
mId = id;
}
}

View File

@@ -48,6 +48,11 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
return KEY;
}
void setIdAndRule(String id, AutomaticZenRule rule) {
mId = id;
mRule = rule;
}
@Override
public boolean isAvailable() {
return mRule != null && mId != null;
@@ -74,11 +79,6 @@ public class ZenAutomaticRuleSwitchPreferenceController extends
}
}
public void onResume(AutomaticZenRule rule, String id) {
mRule = rule;
mId = id;
}
public void updateState(Preference preference) {
if (mRule != null) {
mSwitchBar.updateStatus(mRule.isEnabled());

View File

@@ -45,7 +45,6 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
private final String CUSTOM_BEHAVIOR_KEY = "zen_custom_setting";
protected Context mContext;
protected boolean mDisableListeners;
protected AutomaticZenRule mRule;
protected String mId;
@@ -60,9 +59,8 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
abstract protected void updateControlsInternal();
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mContext = getActivity();
public void onAttach(Context context) {
super.onAttach(context);
final Intent intent = getActivity().getIntent();
if (DEBUG) Log.d(TAG, "onCreate getIntent()=" + intent);
@@ -83,7 +81,14 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
}
if (DEBUG) Log.d(TAG, "mId=" + mId);
if (refreshRuleOrFinish()) {
refreshRuleOrFinish();
}
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
if (isFinishingOrDestroyed()) {
return;
}
@@ -133,15 +138,12 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
protected void updateHeader() {
final PreferenceScreen screen = getPreferenceScreen();
mSwitch.onResume(mRule, mId);
mSwitch.displayPreference(screen);
updatePreference(mSwitch);
mHeader.onResume(mRule, mId);
mHeader.displayPreference(screen);
updatePreference(mHeader);
mActionButtons.onResume(mRule, mId);
mActionButtons.displayPreference(screen);
updatePreference(mActionButtons);
}
@@ -162,6 +164,9 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
private boolean refreshRuleOrFinish() {
mRule = getZenRule();
if (DEBUG) Log.d(TAG, "mRule=" + mRule);
mHeader.setRule(mRule);
mSwitch.setIdAndRule(mId, mRule);
mActionButtons.setIdAndRule(mId, mRule);
if (!setRule(mRule)) {
toastAndFinish();
return true;

View File

@@ -39,11 +39,9 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
implements PreferenceControllerMixin {
public static final String KEY = "zen_action_buttons";
private AutomaticZenRule mRule;
private final PreferenceFragmentCompat mFragment;
private String mId;
private PreferenceFragmentCompat mFragment;
private ActionButtonsPreference mButtonsPref;
private AutomaticZenRule mRule;
public ZenRuleButtonsPreferenceController(Context context, PreferenceFragmentCompat fragment,
Lifecycle lc) {
@@ -51,6 +49,10 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
mFragment = fragment;
}
void setIdAndRule(String id, AutomaticZenRule rule) {
mId = id;
mRule = rule;
}
@Override
public boolean isAvailable() {
@@ -60,7 +62,7 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
@Override
public void displayPreference(PreferenceScreen screen) {
if (isAvailable()) {
mButtonsPref = ((ActionButtonsPreference) screen.findPreference(KEY))
((ActionButtonsPreference) screen.findPreference(KEY))
.setButton1Text(R.string.zen_mode_rule_name_edit)
.setButton1Icon(com.android.internal.R.drawable.ic_mode_edit)
.setButton1OnClickListener(new EditRuleNameClickListener())
@@ -116,9 +118,4 @@ public class ZenRuleButtonsPreferenceController extends AbstractZenModePreferenc
});
}
}
protected void onResume(AutomaticZenRule rule, String id) {
mRule = rule;
mId = id;
}
}

View File

@@ -18,31 +18,27 @@ package com.android.settings.notification.zen;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
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 static org.robolectric.RuntimeEnvironment.application;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Looper;
import androidx.fragment.app.FragmentActivity;
import androidx.test.core.app.ApplicationProvider;
import com.android.settings.R;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.shadows.ShadowToast;
import java.util.ArrayList;
@@ -57,42 +53,32 @@ public class ZenModeEventRuleSettingsTest {
@Mock
private Intent mIntent;
@Mock
private NotificationManager mNotificationManager;
private TestFragment mFragment;
private ZenModeEventRuleSettings mFragment;
private Context mContext;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowApplication shadowApplication = ShadowApplication.getInstance();
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
mContext = application;
mContext = ApplicationProvider.getApplicationContext();
mFragment = spy(new TestFragment());
mFragment.onAttach(application);
doReturn(mActivity).when(mFragment).getActivity();
Resources res = application.getResources();
doReturn(res).when(mFragment).getResources();
Resources res = mContext.getResources();
when(mActivity.getTheme()).thenReturn(res.newTheme());
when(mActivity.getIntent()).thenReturn(mIntent);
when(mActivity.getResources()).thenReturn(res);
when(mActivity.getMainLooper()).thenReturn(mock(Looper.class));
mFragment = spy(new ZenModeEventRuleSettings());
when(mFragment.getActivity()).thenReturn(mActivity);
when(mFragment.getContext()).thenReturn(mContext);
when(mFragment.getResources()).thenReturn(res);
mFragment.onAttach(mContext);
}
@Test
@Ignore
public void onCreate_noRuleId_shouldToastAndFinishAndNoCrash() {
public void onAttach_noRuleId_shouldToastAndFinishAndNoCrash() {
final String expected = mContext.getString(R.string.zen_mode_rule_not_found_text);
mFragment.onCreate(null);
// verify the toast
assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(expected);
@@ -110,12 +96,4 @@ public class ZenModeEventRuleSettingsTest {
mFragment.addCalendar(1234, "calName", 3, calendarsList);
assertThat(calendarsList.size()).isEqualTo(1);
}
private static class TestFragment extends ZenModeEventRuleSettings {
@Override
protected Object getSystemService(final String name) {
return null;
}
}
}