Merge "Remove all reference to SmsMirroring in Android Settings."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 1740b2b..f5c368f 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -2893,12 +2893,12 @@
<category android:name="android.intent.category.VOICE_LAUNCH" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.WifiCallingSettings" />
+ android:value="com.android.settings.wifi.calling.WifiCallingSettings" />
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
android:value="true" />
</activity>
- <activity android:name=".wifi.WifiCallingSuggestionActivity"
+ <activity android:name=".wifi.calling.WifiCallingSuggestionActivity"
android:label="@string/wifi_calling_settings_title"
android:icon="@drawable/ic_settings_wireless">
<intent-filter>
@@ -2906,7 +2906,7 @@
<category android:name="com.android.settings.suggested.category.FIRST_IMPRESSION" />
</intent-filter>
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.WifiCallingSettings" />
+ android:value="com.android.settings.wifi.calling.WifiCallingSettings" />
<meta-data android:name="com.android.settings.dismiss"
android:value="10,14,30" />
<meta-data android:name="com.android.settings.title"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index b1278a6..d7a4586 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -6478,6 +6478,7 @@
<string name="help_uri_process_stats_apps" translatable="false"></string>
<string name="help_uri_private_dns" translatable="false"></string>
<string name="help_uri_about_phone_v2" translatable="false"></string>
+ <string name="help_uri_wifi_calling" translatable="false"></string>
<!-- User account title [CHAR LIMIT=30] -->
<string name="user_account_title">Account for content</string>
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 76def2c..c75b0c6 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -28,7 +28,7 @@
import com.android.settings.TestingSettings;
import com.android.settings.TetherSettings;
import com.android.settings.TrustedCredentialsSettings;
-import com.android.settings.WifiCallingSettings;
+import com.android.settings.wifi.calling.WifiCallingSettings;
import com.android.settings.accessibility.AccessibilitySettings;
import com.android.settings.accessibility.AccessibilitySettingsForSetupWizard;
import com.android.settings.accessibility.CaptionPropertiesFragment;
diff --git a/src/com/android/settings/dashboard/DashboardSummary.java b/src/com/android/settings/dashboard/DashboardSummary.java
index 690c795..8ddef1c 100644
--- a/src/com/android/settings/dashboard/DashboardSummary.java
+++ b/src/com/android/settings/dashboard/DashboardSummary.java
@@ -55,7 +55,7 @@
FocusListener, SuggestionControllerMixin.SuggestionControllerHost {
public static final boolean DEBUG = false;
private static final boolean DEBUG_TIMING = false;
- private static final int MAX_WAIT_MILLIS = 700;
+ private static final int MAX_WAIT_MILLIS = 3000;
private static final String TAG = "DashboardSummary";
private static final String EXTRA_SCROLL_POSITION = "scroll_position";
diff --git a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
index 8523273..07ffb8a 100644
--- a/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImpl.java
@@ -37,7 +37,7 @@
import com.android.settings.password.ScreenLockSuggestionActivity;
import com.android.settings.support.NewDeviceIntroSuggestionActivity;
import com.android.settings.wallpaper.WallpaperSuggestionActivity;
-import com.android.settings.wifi.WifiCallingSuggestionActivity;
+import com.android.settings.wifi.calling.WifiCallingSuggestionActivity;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.drawer.Tile;
import com.android.settingslib.suggestions.SuggestionControllerMixin;
diff --git a/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java b/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java
index 79075ca..62fc8c9 100644
--- a/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java
+++ b/src/com/android/settings/datetime/timezone/TimeZoneAdapter.java
@@ -35,6 +35,7 @@
import java.util.Collections;
import java.util.Date;
import java.util.List;
+import java.util.Locale;
/**
* Adapter for showing {@link TimeZoneInfo} objects in a recycler view.
@@ -55,7 +56,11 @@
TimeZoneAdapter(View.OnClickListener onClickListener, Context context) {
mOnClickListener = onClickListener;
mContext = context;
- mTimeFormat = DateFormat.getTimeInstance(SimpleDateFormat.SHORT);
+ // Use android.text.format.DateFormat to observe 24-hour settings and find the best pattern
+ // using ICU with skeleton.
+ mTimeFormat = new SimpleDateFormat(
+ android.text.format.DateFormat.getTimeFormatString(context),
+ Locale.getDefault());
mDateFormat = DateFormat.getDateInstance(SimpleDateFormat.MEDIUM);
mDateFormat.setContext(DisplayContext.CAPITALIZATION_NONE);
mCurrentTimeZone = TimeZone.getDefault().getID();
diff --git a/src/com/android/settings/fuelgauge/InactiveApps.java b/src/com/android/settings/fuelgauge/InactiveApps.java
index f91a5c6..ac09a57 100644
--- a/src/com/android/settings/fuelgauge/InactiveApps.java
+++ b/src/com/android/settings/fuelgauge/InactiveApps.java
@@ -16,12 +16,21 @@
package com.android.settings.fuelgauge;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_ACTIVE;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_EXEMPTED;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_FREQUENT;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_NEVER;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_RARE;
+import static android.app.usage.UsageStatsManager.STANDBY_BUCKET_WORKING_SET;
+
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
import android.os.Bundle;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.Preference.OnPreferenceClickListener;
import android.support.v7.preference.PreferenceGroup;
@@ -29,10 +38,22 @@
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.widget.RadioButtonPreference;
import java.util.List;
-public class InactiveApps extends SettingsPreferenceFragment implements OnPreferenceClickListener {
+public class InactiveApps extends SettingsPreferenceFragment
+ implements Preference.OnPreferenceChangeListener {
+
+ private static final CharSequence[] SETTABLE_BUCKETS_NAMES =
+ {"ACTIVE", "WORKING_SET", "FREQUENT", "RARE"};
+
+ private static final CharSequence[] SETTABLE_BUCKETS_VALUES = {
+ Integer.toString(STANDBY_BUCKET_ACTIVE),
+ Integer.toString(STANDBY_BUCKET_WORKING_SET),
+ Integer.toString(STANDBY_BUCKET_FREQUENT),
+ Integer.toString(STANDBY_BUCKET_RARE)
+ };
private UsageStatsManager mUsageStats;
@@ -68,29 +89,51 @@
List<ResolveInfo> apps = pm.queryIntentActivities(launcherIntent, 0);
for (ResolveInfo app : apps) {
String packageName = app.activityInfo.applicationInfo.packageName;
- Preference p = new Preference(getPrefContext());
+ ListPreference p = new ListPreference(getPrefContext());
p.setTitle(app.loadLabel(pm));
p.setIcon(app.loadIcon(pm));
p.setKey(packageName);
+ p.setEntries(SETTABLE_BUCKETS_NAMES);
+ p.setEntryValues(SETTABLE_BUCKETS_VALUES);
updateSummary(p);
- p.setOnPreferenceClickListener(this);
+ p.setOnPreferenceChangeListener(this);
screen.addPreference(p);
}
}
- private void updateSummary(Preference p) {
- boolean inactive = mUsageStats.isAppInactive(p.getKey());
- p.setSummary(inactive
- ? R.string.inactive_app_inactive_summary
- : R.string.inactive_app_active_summary);
+ static String bucketToName(int bucket) {
+ switch (bucket) {
+ case STANDBY_BUCKET_EXEMPTED: return "EXEMPTED";
+ case STANDBY_BUCKET_ACTIVE: return "ACTIVE";
+ case STANDBY_BUCKET_WORKING_SET: return "WORKING_SET";
+ case STANDBY_BUCKET_FREQUENT: return "FREQUENT";
+ case STANDBY_BUCKET_RARE: return "RARE";
+ case STANDBY_BUCKET_NEVER: return "NEVER";
+ }
+ return "";
+ }
+
+ private void updateSummary(ListPreference p) {
+ final Resources res = getActivity().getResources();
+ final int appBucket = mUsageStats.getAppStandbyBucket(p.getKey());
+ final String bucketName = bucketToName(appBucket);
+ p.setSummary(res.getString(R.string.standby_bucket_summary, bucketName));
+ // Buckets outside of the range of the dynamic ones are only used for special
+ // purposes and can either not be changed out of, or might have undesirable
+ // side-effects in combination with other assumptions.
+ final boolean changeable = appBucket >= STANDBY_BUCKET_ACTIVE
+ && appBucket <= STANDBY_BUCKET_RARE;
+ if (changeable) {
+ p.setValue(Integer.toString(appBucket));
+ }
+ p.setEnabled(changeable);
}
@Override
- public boolean onPreferenceClick(Preference preference) {
- String packageName = preference.getKey();
- mUsageStats.setAppInactive(packageName, !mUsageStats.isAppInactive(packageName));
- updateSummary(preference);
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mUsageStats.setAppStandbyBucket(preference.getKey(), Integer.parseInt((String) newValue));
+ updateSummary((ListPreference) preference);
return false;
}
}
diff --git a/src/com/android/settings/search/actionbar/SearchMenuController.java b/src/com/android/settings/search/actionbar/SearchMenuController.java
index f3a9285..1729ccd 100644
--- a/src/com/android/settings/search/actionbar/SearchMenuController.java
+++ b/src/com/android/settings/search/actionbar/SearchMenuController.java
@@ -28,6 +28,7 @@
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.SearchFeatureProvider;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.ObservableFragment;
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
@@ -41,6 +42,10 @@
host.getLifecycle().addObserver(new SearchMenuController(host));
}
+ public static void init(@NonNull ObservableFragment host) {
+ host.getLifecycle().addObserver(new SearchMenuController(host));
+ }
+
private SearchMenuController(@NonNull Fragment host) {
mHost = host;
}
diff --git a/src/com/android/settings/support/actionbar/HelpMenuController.java b/src/com/android/settings/support/actionbar/HelpMenuController.java
index a95d44e..1188fc2 100644
--- a/src/com/android/settings/support/actionbar/HelpMenuController.java
+++ b/src/com/android/settings/support/actionbar/HelpMenuController.java
@@ -27,6 +27,7 @@
import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.ObservableFragment;
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
@@ -41,6 +42,10 @@
host.getLifecycle().addObserver(new HelpMenuController(host));
}
+ public static void init(@NonNull ObservableFragment host) {
+ host.getLifecycle().addObserver(new HelpMenuController(host));
+ }
+
private HelpMenuController(@NonNull Fragment host) {
mHost = host;
}
diff --git a/src/com/android/settings/WifiCallingSettings.java b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
similarity index 80%
rename from src/com/android/settings/WifiCallingSettings.java
rename to src/com/android/settings/wifi/calling/WifiCallingSettings.java
index e872fb8..7bab07a 100644
--- a/src/com/android/settings/WifiCallingSettings.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettings.java
@@ -14,11 +14,10 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.wifi.calling;
import android.app.Fragment;
import android.app.FragmentManager;
-import android.content.Context;
import android.os.Bundle;
import android.support.v13.app.FragmentPagerAdapter;
import android.telephony.SubscriptionInfo;
@@ -28,9 +27,13 @@
import android.view.View;
import android.view.ViewGroup;
-import com.android.ims.ImsConfig;
import com.android.ims.ImsManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.search.actionbar.SearchMenuController;
+import com.android.settings.support.actionbar.HelpMenuController;
+import com.android.settings.support.actionbar.HelpResourceProvider;
import com.android.settings.widget.RtlCompatibleViewPager;
import com.android.settings.widget.SlidingTabLayout;
@@ -40,7 +43,7 @@
* "Wi-Fi Calling settings" screen. This is the container fragment which holds
* {@link WifiCallingSettingsForSub} fragments.
*/
-public class WifiCallingSettings extends SettingsPreferenceFragment {
+public class WifiCallingSettings extends InstrumentedFragment implements HelpResourceProvider {
private static final String TAG = "WifiCallingSettings";
private List<SubscriptionInfo> mSil;
@@ -71,6 +74,10 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
+ setHasOptionsMenu(true);
+ SearchMenuController.init(this /* host */);
+ HelpMenuController.init(this /* host */);
+
// TODO: besides in onCreate, we should also update subList when SIM / Sub status
// changes.
updateSubList();
@@ -87,6 +94,11 @@
}
}
+ @Override
+ public int getHelpResource() {
+ return R.string.help_uri_wifi_calling;
+ }
+
private final class WifiCallingViewPagerAdapter extends FragmentPagerAdapter {
private final RtlCompatibleViewPager mViewPager;
@@ -105,6 +117,7 @@
public Fragment getItem(int position) {
Log.d(TAG, "Adapter getItem " + position);
final Bundle args = new Bundle();
+ args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
args.putInt(WifiCallingSettingsForSub.FRAGMENT_BUNDLE_SUBID,
mSil.get(position).getSubscriptionId());
WifiCallingSettingsForSub fragment = new WifiCallingSettingsForSub();
@@ -132,26 +145,6 @@
}
}
- public static int getWfcModeSummary(Context context, int wfcMode) {
- int resId = com.android.internal.R.string.wifi_calling_off_summary;
- if (ImsManager.isWfcEnabledByUser(context)) {
- switch (wfcMode) {
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_ONLY:
- resId = com.android.internal.R.string.wfc_mode_wifi_only_summary;
- break;
- case ImsConfig.WfcModeFeatureValueConstants.CELLULAR_PREFERRED:
- resId = com.android.internal.R.string.wfc_mode_cellular_preferred_summary;
- break;
- case ImsConfig.WfcModeFeatureValueConstants.WIFI_PREFERRED:
- resId = com.android.internal.R.string.wfc_mode_wifi_preferred_summary;
- break;
- default:
- Log.e(TAG, "Unexpected WFC mode value: " + wfcMode);
- }
- }
- return resId;
- }
-
private void updateSubList() {
mSil = SubscriptionManager.from(getActivity()).getActiveSubscriptionInfoList();
@@ -159,7 +152,7 @@
if (mSil == null) {
return;
}
- for (int i = 0; i < mSil.size();) {
+ for (int i = 0; i < mSil.size(); ) {
ImsManager imsManager = ImsManager.getInstance(getActivity(),
mSil.get(i).getSimSlotIndex());
if (!imsManager.isWfcEnabledByPlatform()) {
diff --git a/src/com/android/settings/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
similarity index 98%
rename from src/com/android/settings/WifiCallingSettingsForSub.java
rename to src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index ba5ba84..2bfd796 100644
--- a/src/com/android/settings/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings;
+package com.android.settings.wifi.calling;
import android.app.Activity;
import android.app.AlertDialog;
@@ -45,6 +45,10 @@
import com.android.ims.ImsManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.Phone;
+import com.android.settings.R;
+import com.android.settings.SettingsActivity;
+import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.Utils;
import com.android.settings.widget.SwitchBar;
/**
@@ -54,7 +58,7 @@
public class WifiCallingSettingsForSub extends SettingsPreferenceFragment
implements SwitchBar.OnSwitchChangeListener,
Preference.OnPreferenceChangeListener {
- private static final String TAG = "WifiCallingSettingsForSub";
+ private static final String TAG = "WifiCallingForSub";
//String keys for preference lookup
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
@@ -130,12 +134,6 @@
}
};
- @Override
- public int getHelpResource() {
- // Helper resource is already defined in the container fragment.
- return 0;
- }
-
private final OnPreferenceClickListener mUpdateAddressListener =
new OnPreferenceClickListener() {
/*
@@ -226,8 +224,7 @@
// SubId should always be specified when creating this fragment. Either through
// fragment.setArguments() or through savedInstanceState.
- if (getArguments() != null && getArguments().containsKey(FRAGMENT_BUNDLE_SUBID))
- {
+ if (getArguments() != null && getArguments().containsKey(FRAGMENT_BUNDLE_SUBID)) {
mSubId = getArguments().getInt(FRAGMENT_BUNDLE_SUBID);
} else if (savedInstanceState != null) {
mSubId = savedInstanceState.getInt(
diff --git a/src/com/android/settings/wifi/WifiCallingSuggestionActivity.java b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
similarity index 96%
rename from src/com/android/settings/wifi/WifiCallingSuggestionActivity.java
rename to src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
index c3c7adb..9a50a83 100644
--- a/src/com/android/settings/wifi/WifiCallingSuggestionActivity.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSuggestionActivity.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.wifi;
+package com.android.settings.wifi.calling;
import android.content.Context;
diff --git a/tests/robotests/assets/grandfather_not_implementing_indexable b/tests/robotests/assets/grandfather_not_implementing_indexable
index 5a3c044..748dc94 100644
--- a/tests/robotests/assets/grandfather_not_implementing_indexable
+++ b/tests/robotests/assets/grandfather_not_implementing_indexable
@@ -60,8 +60,7 @@
com.android.settings.applications.appinfo.PictureInPictureDetails
com.android.settings.ApnSettings
com.android.settings.PrivacySettings
-com.android.settings.WifiCallingSettings
-com.android.settings.WifiCallingSettingsForSub
+com.android.settings.wifi.calling.WifiCallingSettingsForSub
com.android.settings.password.SetupChooseLockGeneric$SetupChooseLockGenericFragment
com.android.settings.SetupRedactionInterstitial$SetupRedactionInterstitialFragment
com.android.settings.security.trustagent.TrustAgentSettings
diff --git a/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java
index 5f29a0b..1377f1d 100644
--- a/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/datetime/timezone/TimeZoneAdapterTest.java
@@ -15,13 +15,18 @@
*/
package com.android.settings.datetime.timezone;
+import android.content.Context;
import android.icu.util.TimeZone;
+import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
+
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
+
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,8 +34,11 @@
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
import java.util.Collections;
+import java.util.Locale;
import static com.google.common.truth.Truth.assertThat;
@@ -38,17 +46,39 @@
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
- SettingsShadowResources.SettingsShadowTheme.class})
+ SettingsShadowResources.SettingsShadowTheme.class,
+ TimeZoneAdapterTest.ShadowDataFormat.class})
public class TimeZoneAdapterTest {
@Mock
private View.OnClickListener mOnClickListener;
private TimeZoneAdapter mTimeZoneAdapter;
+ private Context mContext;
+ private Locale mDefaultLocale;
+
@Before
- public void setUp() {
+ public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, RuntimeEnvironment.application);
+ mContext = RuntimeEnvironment.application;
+ mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
+ mDefaultLocale = Locale.getDefault();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ Locale.setDefault(mDefaultLocale);
+ }
+
+ @Implements(android.text.format.DateFormat.class)
+ public static class ShadowDataFormat {
+
+ public static String mTimeFormatString = "";
+
+ @Implementation
+ public static String getTimeFormatString(Context context) {
+ return mTimeFormatString;
+ }
}
@Test
@@ -89,6 +119,38 @@
assertThat(viewHolder.mDstView.getVisibility()).isEqualTo(View.GONE);
}
+ @Test
+ public void bindViewHolder_on24Hour() {
+ Locale.setDefault(Locale.US);
+ ShadowDataFormat.mTimeFormatString = "HH:mm";
+ mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
+
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+
+ final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
+
+ final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
+ mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
+ assertThat(viewHolder.mTimeView.getText().toString()).hasLength(5);
+ }
+
+ @Test
+ public void bindViewHolder_on12Hour() {
+ Locale.setDefault(Locale.US);
+ ShadowDataFormat.mTimeFormatString = "hh:mm a";
+ mTimeZoneAdapter = new TimeZoneAdapter(mOnClickListener, mContext);
+
+ final TimeZoneInfo tzi = dummyTimeZoneInfo(TimeZone.getTimeZone("Etc/UTC"));
+ mTimeZoneAdapter.setTimeZoneInfos(Collections.singletonList(tzi));
+
+ final FrameLayout parent = new FrameLayout(RuntimeEnvironment.application);
+
+ final ViewHolder viewHolder = (ViewHolder) mTimeZoneAdapter.createViewHolder(parent, TimeZoneAdapter.VIEW_TYPE_NORMAL);
+ mTimeZoneAdapter.bindViewHolder(viewHolder, 0);
+ assertThat(viewHolder.mTimeView.getText().toString()).hasLength(8);
+ }
+
// Pick an arbitrary time zone that's not the current default.
private static TimeZone getNonDefaultTimeZone() {
final String[] availableIDs = TimeZone.getAvailableIDs();
diff --git a/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
index e1c77cd..d6e8c63 100644
--- a/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
+++ b/tests/robotests/src/com/android/settings/search/actionbar/SearchMenuControllerTest.java
@@ -18,6 +18,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.os.Bundle;
@@ -27,6 +28,7 @@
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.ObservableFragment;
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
import org.junit.Before;
@@ -42,26 +44,47 @@
@Mock
private Menu mMenu;
- private TestFragment mHost;
+ private TestPreferenceFragment mPreferenceHost;
+ private ObservableFragment mHost;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mHost = new TestFragment();
+ mHost = new ObservableFragment();
+ mPreferenceHost = new TestPreferenceFragment();
+
+ when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
+ .thenReturn(mock(MenuItem.class));
}
@Test
- public void init_shouldAddMenu() {
- when(mMenu.add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu))
- .thenReturn(mock(MenuItem.class));
+ public void init_prefFragment_shouldAddMenu() {
+ SearchMenuController.init(mPreferenceHost);
+ mPreferenceHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
+ verify(mMenu).add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu);
+ }
+
+ @Test
+ public void init_observableFragment_shouldAddMenu() {
SearchMenuController.init(mHost);
mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
verify(mMenu).add(Menu.NONE, Menu.NONE, 0 /* order */, R.string.search_menu);
}
- public static class TestFragment extends ObservablePreferenceFragment {
+ @Test
+ public void init_doNotNeedSearchIcon_shouldNotAddMenu() {
+ final Bundle args = new Bundle();
+ args.putBoolean(SearchMenuController.NEED_SEARCH_ICON_IN_ACTION_BAR, false);
+ mHost.setArguments(args);
+
+ SearchMenuController.init(mHost);
+ mHost.getLifecycle().onCreateOptionsMenu(mMenu, null /* inflater */);
+ verifyZeroInteractions(mMenu);
+ }
+
+ public static class TestPreferenceFragment extends ObservablePreferenceFragment {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
diff --git a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
index 677bf41..9dff925 100644
--- a/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
+++ b/tests/robotests/src/com/android/settings/suggestions/SettingsSuggestionsTest.java
@@ -68,7 +68,7 @@
@Test
public void wifiCallingSuggestion_isValid() {
- assertSuggestionEquals("com.android.settings.wifi.WifiCallingSuggestionActivity",
+ assertSuggestionEquals("com.android.settings.wifi.calling.WifiCallingSuggestionActivity",
CATEGORY_FIRST_IMPRESSION,
R.string.wifi_calling_suggestion_title, R.string.wifi_calling_suggestion_summary);
}
diff --git a/tests/unit/AndroidManifest.xml b/tests/unit/AndroidManifest.xml
index b22c01b..eccbac3 100644
--- a/tests/unit/AndroidManifest.xml
+++ b/tests/unit/AndroidManifest.xml
@@ -53,6 +53,15 @@
<meta-data android:name="com.android.settings.summary" android:resource="@string/manufacturer_settings_summary" />
<meta-data android:name="com.android.settings.icon" android:resource="@drawable/ic_settings_applications" />
</activity>
+
+ <service android:name="com.android.settings.accounts.TestAuthService">
+ <intent-filter>
+ <action android:name="android.accounts.AccountAuthenticator" />
+ </intent-filter>
+ <meta-data android:name="android.accounts.AccountAuthenticator"
+ android:resource="@xml/authenticator" />
+ </service>
+
</application>
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/unit/res/values/strings.xml b/tests/unit/res/values/strings.xml
index 35e201a..620bb04 100644
--- a/tests/unit/res/values/strings.xml
+++ b/tests/unit/res/values/strings.xml
@@ -28,4 +28,7 @@
<string name="manufacturer_hello" translatable="false">Hello Manufacturer!</string>
<string name="manufacturer_settings_title" translatable="false">Manufacturer</string>
<string name="manufacturer_settings_summary" translatable="false">Manufacturer hook that can be used to start activity of choice</string>
+ <string name="account_auth_label" translatable="false">Settings Test Account</string>
+ <string name="account_type" translatable="false">com.settingstest.account-prefs</string>
+ <string name="account_pref_title" translatable="false">Test preference for external account</string>
</resources>
diff --git a/tests/unit/res/xml/account_preferences.xml b/tests/unit/res/xml/account_preferences.xml
new file mode 100644
index 0000000..b391759
--- /dev/null
+++ b/tests/unit/res/xml/account_preferences.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+ <SwitchPreference
+ android:key="account_test_switch"
+ android:title="@string/account_pref_title" />
+
+</PreferenceScreen>
+
diff --git a/tests/unit/res/xml/authenticator.xml b/tests/unit/res/xml/authenticator.xml
new file mode 100644
index 0000000..92bf774
--- /dev/null
+++ b/tests/unit/res/xml/authenticator.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<account-authenticator
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:label="@string/account_auth_label"
+ android:icon="@drawable/ic_settings_applications"
+ android:accountType="@string/account_type"
+ android:accountPreferences="@xml/account_preferences" />
+
diff --git a/tests/unit/src/com/android/settings/accounts/AccountsSettingsTest.java b/tests/unit/src/com/android/settings/accounts/AccountsSettingsTest.java
new file mode 100644
index 0000000..7218efe
--- /dev/null
+++ b/tests/unit/src/com/android/settings/accounts/AccountsSettingsTest.java
@@ -0,0 +1,90 @@
+/*
+ * 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.accounts;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.accounts.Account;
+import android.accounts.AccountManager;
+import android.content.Context;
+import android.content.Intent;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.support.test.uiautomator.UiDevice;
+import android.support.test.uiautomator.UiObject;
+import android.support.test.uiautomator.UiSelector;
+import android.support.test.uiautomator.UiScrollable;
+import android.support.test.uiautomator.UiObjectNotFoundException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidJUnit4.class)
+@SmallTest
+public class AccountsSettingsTest {
+
+ private static final String ACCOUNTS = "Accounts";
+ private static final String ACCOUNT_TYPE = "com.settingstest.account-prefs";
+ private static final String PREF_TITLE = "Test preference for external account";
+
+ private UiDevice mDevice;
+ private Context mContext;
+ private String mTargetPackage;
+
+ @Before
+ public void setUp() {
+ mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mContext = InstrumentationRegistry.getTargetContext();
+ mTargetPackage = mContext.getPackageName();
+ }
+
+ @Test
+ public void testExternalAccountInfoExists() throws UiObjectNotFoundException {
+ // add a test account
+ final String testAccountName = "Test Account";
+ final Account account = new Account(testAccountName, ACCOUNT_TYPE);
+ final AccountManager accountManager = AccountManager.get(mContext);
+ final boolean accountAdded =
+ accountManager.addAccountExplicitly(account, null /* password */, null /* userdata */);
+ assertThat(accountAdded).isTrue();
+
+ // launch Accounts Settings and select the test account
+ launchAccountsSettings();
+ mDevice.findObject(new UiSelector().text(testAccountName)).click();
+ final UiObject testPreference = mDevice.findObject(new UiSelector().text(PREF_TITLE));
+ // remove test account
+ accountManager.removeAccountExplicitly(account);
+
+ assertThat(testPreference.exists()).isTrue();
+ }
+
+ private void launchAccountsSettings() throws UiObjectNotFoundException {
+ // launch settings
+ Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
+ .addCategory(Intent.CATEGORY_LAUNCHER)
+ .setPackage(mTargetPackage)
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ mContext.startActivity(settingsIntent);
+ // selects Accounts
+ final UiScrollable settings = new UiScrollable(
+ new UiSelector().packageName(mTargetPackage).scrollable(true));
+ final String titleAccounts = ACCOUNTS;
+ settings.scrollTextIntoView(titleAccounts);
+ mDevice.findObject(new UiSelector().text(titleAccounts)).click();
+ }
+}
diff --git a/tests/unit/src/com/android/settings/accounts/Authenticator.java b/tests/unit/src/com/android/settings/accounts/Authenticator.java
new file mode 100644
index 0000000..a2413dc
--- /dev/null
+++ b/tests/unit/src/com/android/settings/accounts/Authenticator.java
@@ -0,0 +1,74 @@
+/*
+ * 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.accounts;
+
+import android.accounts.AbstractAccountAuthenticator;
+import android.accounts.Account;
+import android.accounts.AccountAuthenticatorResponse;
+import android.accounts.AccountManager;
+import android.accounts.NetworkErrorException;
+import android.content.Context;
+import android.os.Bundle;
+
+public class Authenticator extends AbstractAccountAuthenticator {
+
+ public Authenticator(Context context) {
+ super(context);
+ }
+
+ @Override
+ public Bundle editProperties(AccountAuthenticatorResponse r, String s) {
+ return null;
+ }
+
+ @Override
+ public Bundle addAccount(AccountAuthenticatorResponse r, String s, String s2, String[] strings,
+ Bundle bundle) throws NetworkErrorException {
+ final Bundle result = new Bundle();
+ result.putString(AccountManager.KEY_ACCOUNT_NAME, "Test Account");
+ result.putString(AccountManager.KEY_ACCOUNT_TYPE, s);
+ return result;
+ }
+
+ @Override
+ public Bundle confirmCredentials(AccountAuthenticatorResponse r, Account account, Bundle bundle)
+ throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle getAuthToken(AccountAuthenticatorResponse r, Account account, String s,
+ Bundle bundle) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public String getAuthTokenLabel(String s) {
+ return s;
+ }
+
+ @Override
+ public Bundle updateCredentials(AccountAuthenticatorResponse r, Account account, String s,
+ Bundle bundle) throws NetworkErrorException {
+ return null;
+ }
+
+ @Override
+ public Bundle hasFeatures(AccountAuthenticatorResponse r, Account account, String[] strings)
+ throws NetworkErrorException {
+ return null;
+ }
+}
diff --git a/tests/unit/src/com/android/settings/accounts/TestAuthService.java b/tests/unit/src/com/android/settings/accounts/TestAuthService.java
new file mode 100644
index 0000000..574e9b5
--- /dev/null
+++ b/tests/unit/src/com/android/settings/accounts/TestAuthService.java
@@ -0,0 +1,36 @@
+/*
+ * 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.accounts;
+
+import android.app.Service;
+import android.content.Intent;
+import android.os.IBinder;
+
+public class TestAuthService extends Service {
+
+ private Authenticator mAuthenticator;
+
+ @Override
+ public void onCreate() {
+ mAuthenticator = new Authenticator(this);
+ }
+
+ @Override
+ public IBinder onBind(Intent intent) {
+ return mAuthenticator.getIBinder();
+ }
+
+}