Merge "Refactor passwords/pins/patterns to byte[]"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6724ff5..a5586f7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3009,6 +3009,7 @@
android:theme="@style/Theme.BottomDialog"
android:excludeFromRecents="true"
android:launchMode="singleTop"
+ android:taskAffinity=".panel.SettingsPanelActivity"
android:exported="true">
<intent-filter>
<action android:name="android.settings.panel.action.INTERNET_CONNECTIVITY" />
diff --git a/res/layout-land/panel_layout.xml b/res/layout-land/panel_layout.xml
index 3975bfe..049fd0b 100644
--- a/res/layout-land/panel_layout.xml
+++ b/res/layout-land/panel_layout.xml
@@ -20,7 +20,7 @@
android:orientation="vertical">
<TextView
- android:id="@+id/title"
+ android:id="@+id/panel_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
diff --git a/res/layout/settings_panel.xml b/res/layout/settings_panel.xml
index aec898c..3405ef0 100644
--- a/res/layout/settings_panel.xml
+++ b/res/layout/settings_panel.xml
@@ -16,4 +16,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_content"
android:layout_height="match_parent"
- android:layout_width="match_parent"/>
\ No newline at end of file
+ android:layout_width="match_parent"
+ android:animateLayoutChanges="true"/>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e01ab3b..90b72e1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2153,6 +2153,10 @@
<string name="wifi_dpp_could_not_add_device">Couldn\u2019t add device</string>
<!-- Title for the fragment to show that device found but naming known [CHAR LIMIT=50] -->
<string name="wifi_dpp_device_found">Device found</string>
+ <!-- Hint for Wi-Fi DPP handshake running [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_sharing_wifi_with_this_device">Sharing Wi\u2011Fi with this device\u2026</string>
+ <!-- Hint for Wi-Fi DPP handshake running [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_connecting">Connecting\u2026</string>
<!-- Label for the try again button [CHAR LIMIT=20]-->
<string name="retry">Retry</string>
<!-- Label for the check box to share a network with other users on the same device -->
@@ -3623,7 +3627,7 @@
<string name="master_clear_final_button_text">Erase everything</string>
<!-- Master clear failed message -->
<string name="master_clear_failed">No reset was performed because the System Clear service isn\u2019t available.</string>
- <!-- Master clear confirmation screen title [CHAR LIMIT=30] -->
+ <!-- Master clear confirmation screen title [CHAR LIMIT=33] -->
<string name="master_clear_confirm_title">Erase all data?</string>
<!-- Error message for users that aren't allowed to factory reset [CHAR LIMIT=none] -->
<string name="master_clear_not_available">Factory reset is not available for this user</string>
diff --git a/res/xml/accessibility_settings.xml b/res/xml/accessibility_settings.xml
index 9cb73a2..da103c5 100644
--- a/res/xml/accessibility_settings.xml
+++ b/res/xml/accessibility_settings.xml
@@ -58,6 +58,14 @@
android:title="@string/screen_zoom_title"
settings:searchable="false"/>
+ <ListPreference
+ android:key="dark_ui_mode_accessibility"
+ android:title="@string/dark_ui_mode"
+ android:dialogTitle="@string/dark_ui_mode_title"
+ android:entries="@array/dark_ui_mode_entries"
+ android:entryValues="@array/dark_ui_mode_values"
+ settings:searchable="false" />
+
<Preference
android:fragment="com.android.settings.accessibility.MagnificationPreferenceFragment"
android:key="magnification_preference_screen"
diff --git a/res/xml/app_and_notification.xml b/res/xml/app_and_notification.xml
index 518379a..9dd5fea 100644
--- a/res/xml/app_and_notification.xml
+++ b/res/xml/app_and_notification.xml
@@ -27,7 +27,8 @@
android:key="all_app_info"
android:title="@string/applications_settings"
android:order="-999"
- android:fragment="com.android.settings.applications.manageapplications.ManageApplications"/>
+ android:fragment="com.android.settings.applications.manageapplications.ManageApplications"
+ settings:controller="com.android.settings.applications.AllAppsInfoPreferenceController"/>
<com.android.settingslib.widget.LayoutPreference
android:key="recent_open_apps"
diff --git a/src/com/android/settings/accessibility/AccessibilitySettings.java b/src/com/android/settings/accessibility/AccessibilitySettings.java
index ee0cb7d..921af04 100644
--- a/src/com/android/settings/accessibility/AccessibilitySettings.java
+++ b/src/com/android/settings/accessibility/AccessibilitySettings.java
@@ -57,6 +57,7 @@
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.display.DarkUIPreferenceController;
import com.android.settings.display.ToggleFontSizePreferenceFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -133,6 +134,8 @@
"accessibility_content_timeout_preference_fragment";
private static final String ACCESSIBILITY_CONTROL_TIMEOUT_PREFERENCE =
"accessibility_control_timeout_preference_fragment";
+ private static final String DARK_UI_MODE_PREFERENCE =
+ "dark_ui_mode_accessibility";
// Extras passed to sub-fragments.
@@ -236,6 +239,8 @@
private SwitchPreference mToggleInversionPreference;
private ColorInversionPreferenceController mInversionPreferenceController;
private AccessibilityHearingAidPreferenceController mHearingAidPreferenceController;
+ private ListPreference mDarkUIModePreference;
+ private DarkUIPreferenceController mDarkUIPreferenceController;
private int mLongPressTimeoutDefault;
@@ -501,6 +506,13 @@
// Vibrations.
mVibrationPreferenceScreen = findPreference(VIBRATION_PREFERENCE_SCREEN);
+
+ // Dark Mode.
+ mDarkUIModePreference = findPreference(DARK_UI_MODE_PREFERENCE);
+ mDarkUIPreferenceController = new DarkUIPreferenceController(getContext(),
+ DARK_UI_MODE_PREFERENCE);
+ mDarkUIPreferenceController.displayPreference(getPreferenceScreen());
+ mDarkUIModePreference.setSummary(mDarkUIPreferenceController.getSummary());
}
private void updateAllPreferences() {
@@ -683,6 +695,9 @@
// If the quick setting is enabled, the preference MUST be enabled.
mInversionPreferenceController.updateState(mToggleInversionPreference);
+ // Dark Mode
+ mDarkUIPreferenceController.updateState(mDarkUIModePreference);
+
// Power button ends calls.
if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_POWER)
&& Utils.isVoiceCapable(getActivity())) {
diff --git a/src/com/android/settings/applications/AllAppsInfoPreferenceController.java b/src/com/android/settings/applications/AllAppsInfoPreferenceController.java
new file mode 100644
index 0000000..d39c6e9
--- /dev/null
+++ b/src/com/android/settings/applications/AllAppsInfoPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * 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.applications;
+
+import android.app.usage.UsageStats;
+import android.content.Context;
+
+import androidx.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+import java.util.List;
+
+public class AllAppsInfoPreferenceController extends BasePreferenceController {
+
+ private List<UsageStats> mRecentApps;
+
+ public AllAppsInfoPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ public void setRecentApps(List<UsageStats> recentApps) {
+ mRecentApps = recentApps;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mRecentApps == null || mRecentApps.isEmpty() ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ // Show total number of installed apps as See all's summary.
+ new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
+ mContext.getPackageManager()) {
+ @Override
+ protected void onCountComplete(int num) {
+ preference.setSummary(mContext.getString(R.string.apps_summary, num));
+ }
+ }.execute();
+ }
+}
diff --git a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
index 4848351..7aaf80d 100644
--- a/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
+++ b/src/com/android/settings/applications/AppAndNotificationDashboardFragment.java
@@ -36,6 +36,10 @@
private static final String TAG = "AppAndNotifDashboard";
+ private boolean mIsFirstLaunch;
+ private RecentAppsPreferenceController mRecentAppsPreferenceController;
+ private AllAppsInfoPreferenceController mAllAppsInfoPreferenceController;
+
@Override
public int getMetricsCategory() {
return SettingsEnums.SETTINGS_APP_NOTIF_CATEGORY;
@@ -61,7 +65,26 @@
super.onAttach(context);
use(SpecialAppAccessPreferenceController.class).setSession(getSettingsLifecycle());
- use(RecentAppsPreferenceController.class).setFragment(this /* fragment */);
+ mRecentAppsPreferenceController = use(RecentAppsPreferenceController.class);
+ mRecentAppsPreferenceController.setFragment(this /* fragment */);
+
+ mAllAppsInfoPreferenceController = use(AllAppsInfoPreferenceController.class);
+ mAllAppsInfoPreferenceController.setRecentApps(
+ mRecentAppsPreferenceController.getRecentApps());
+
+ mIsFirstLaunch = true;
+ }
+
+ @Override
+ public void onResume() {
+ if (!mIsFirstLaunch) {
+ mRecentAppsPreferenceController.reloadData();
+ mAllAppsInfoPreferenceController.setRecentApps(
+ mRecentAppsPreferenceController.getRecentApps());
+ }
+
+ super.onResume();
+ mIsFirstLaunch = false;
}
@Override
diff --git a/src/com/android/settings/applications/RecentAppsPreferenceController.java b/src/com/android/settings/applications/RecentAppsPreferenceController.java
index fe52a8b..c0d18c6 100644
--- a/src/com/android/settings/applications/RecentAppsPreferenceController.java
+++ b/src/com/android/settings/applications/RecentAppsPreferenceController.java
@@ -67,8 +67,6 @@
implements Comparator<UsageStats> {
@VisibleForTesting
- static final String KEY_ALL_APP_INFO = "all_app_info";
- @VisibleForTesting
static final String KEY_DIVIDER = "recent_apps_divider";
private static final String TAG = "RecentAppsCtrl";
@@ -79,8 +77,6 @@
@VisibleForTesting
LayoutPreference mRecentAppsPreference;
@VisibleForTesting
- Preference mAllAppPref;
- @VisibleForTesting
Preference mDivider;
private final PackageManager mPm;
@@ -93,6 +89,7 @@
private Fragment mHost;
private Calendar mCal;
private List<UsageStats> mStats;
+ private List<UsageStats> mRecentApps;
private boolean mHasRecentApps;
static {
@@ -115,6 +112,8 @@
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
mPowerManager = mContext.getSystemService(PowerManager.class);
mUsageStatsManager = mContext.getSystemService(UsageStatsManager.class);
+ mRecentApps = new ArrayList<>();
+ reloadData();
}
public void setFragment(Fragment fragment) {
@@ -123,15 +122,13 @@
@Override
public int getAvailabilityStatus() {
- reloadData();
- return getDisplayableRecentAppList().isEmpty() ? AVAILABLE_UNSEARCHABLE : AVAILABLE;
+ return mRecentApps.isEmpty() ? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
- mAllAppPref = screen.findPreference(KEY_ALL_APP_INFO);
mDivider = screen.findPreference(KEY_DIVIDER);
mRecentAppsPreference = (LayoutPreference) screen.findPreference(getPreferenceKey());
final View view = mRecentAppsPreference.findViewById(R.id.app_entities_header);
@@ -152,19 +149,16 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
+
refreshUi();
// Show total number of installed apps as See all's summary.
new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
mContext.getPackageManager()) {
@Override
protected void onCountComplete(int num) {
- if (mHasRecentApps) {
- mAppEntitiesController.setHeaderDetails(
- mContext.getString(R.string.see_all_apps_title, num));
- mAppEntitiesController.apply();
- } else {
- mAllAppPref.setSummary(mContext.getString(R.string.apps_summary, num));
- }
+ mAppEntitiesController.setHeaderDetails(
+ mContext.getString(R.string.see_all_apps_title, num));
+ mAppEntitiesController.apply();
}
}.execute();
}
@@ -175,16 +169,16 @@
return Long.compare(b.getLastTimeUsed(), a.getLastTimeUsed());
}
+ List<UsageStats> getRecentApps() {
+ return mRecentApps;
+ }
+
@VisibleForTesting
void refreshUi() {
- reloadData();
- final List<UsageStats> recentApps = getDisplayableRecentAppList();
- if (recentApps != null && !recentApps.isEmpty()) {
- mHasRecentApps = true;
- displayRecentApps(recentApps);
+ if (mRecentApps != null && !mRecentApps.isEmpty()) {
+ displayRecentApps();
} else {
- mHasRecentApps = false;
- displayOnlyAppInfo();
+ mDivider.setVisible(false);
}
}
@@ -197,19 +191,14 @@
: mUsageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_BEST, mCal.getTimeInMillis(),
System.currentTimeMillis());
+
+ updateDisplayableRecentAppList();
}
- private void displayOnlyAppInfo() {
- mDivider.setVisible(false);
- mAllAppPref.setTitle(R.string.applications_settings);
- mAllAppPref.setVisible(true);
- mRecentAppsPreference.setVisible(false);
- }
-
- private void displayRecentApps(List<UsageStats> recentApps) {
+ private void displayRecentApps() {
int showAppsCount = 0;
- for (UsageStats stat : recentApps) {
+ for (UsageStats stat : mRecentApps) {
final AppEntityInfo appEntityInfoInfo = createAppEntity(stat);
if (appEntityInfoInfo != null) {
mAppEntitiesController.setAppEntity(showAppsCount++, appEntityInfoInfo);
@@ -220,8 +209,6 @@
}
}
mAppEntitiesController.apply();
- mRecentAppsPreference.setVisible(true);
- mAllAppPref.setVisible(false);
mDivider.setVisible(true);
}
@@ -246,8 +233,8 @@
.build();
}
- private List<UsageStats> getDisplayableRecentAppList() {
- final List<UsageStats> recentApps = new ArrayList<>();
+ private void updateDisplayableRecentAppList() {
+ mRecentApps.clear();
final Map<String, UsageStats> map = new ArrayMap<>();
final int statCount = mStats.size();
for (int i = 0; i < statCount; i++) {
@@ -273,13 +260,12 @@
if (appEntry == null) {
continue;
}
- recentApps.add(stat);
+ mRecentApps.add(stat);
count++;
if (count >= AppEntitiesHeaderController.MAXIMUM_APPS) {
break;
}
}
- return recentApps;
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
index 305281c..370a4df 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
@@ -30,6 +30,7 @@
private static final String TAG = "DeviceAdminListItem";
+ private final UserHandle mUserHandle;
private final String mKey;
private final DeviceAdminInfo mInfo;
private final CharSequence mName;
@@ -39,7 +40,8 @@
public DeviceAdminListItem(Context context, DeviceAdminInfo info) {
mInfo = info;
- mKey = mInfo.getComponent().flattenToString();
+ mUserHandle = new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
+ mKey = mUserHandle.getIdentifier() + "@" + mInfo.getComponent().flattenToString();
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final PackageManager pm = context.getPackageManager();
mName = mInfo.loadLabel(pm);
@@ -48,8 +50,7 @@
} catch (Resources.NotFoundException exception) {
Log.w(TAG, "Setting description to null because can't find resource: " + mKey);
}
- mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm),
- new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo)));
+ mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm), mUserHandle);
}
@Override
@@ -70,8 +71,7 @@
}
public boolean isActive() {
- return mDPM.isAdminActiveAsUser(mInfo.getComponent(),
- DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return mDPM.isAdminActiveAsUser(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
}
public Drawable getIcon() {
@@ -79,16 +79,25 @@
}
public boolean isEnabled() {
- return !mDPM.isRemovingAdmin(mInfo.getComponent(),
- DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return !mDPM.isRemovingAdmin(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
}
public UserHandle getUser() {
- return new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
}
public Intent getLaunchIntent(Context context) {
return new Intent(context, DeviceAdminAdd.class)
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mInfo.getComponent());
}
+
+ /**
+ * Extracts the user id from a device admin info object.
+ *
+ * @param adminInfo the device administrator info.
+ * @return identifier of the user associated with the device admin.
+ */
+ private static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
+ return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
index 319d62f..7b139d9 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
@@ -53,6 +53,9 @@
import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.FooterPreferenceMixinCompat;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -249,8 +252,7 @@
Log.w(TAG, "Unable to load component: " + activeAdmin);
continue;
}
- final DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
- mContext, ai);
+ final DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(mContext, ai);
if (deviceAdminInfo == null) {
continue;
}
@@ -286,7 +288,7 @@
&& alreadyAddedComponents.contains(riComponentName)) {
continue;
}
- DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
+ DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(
mContext, resolveInfo.activityInfo);
// add only visible ones (note: active admins are added regardless of visibility)
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
@@ -297,4 +299,20 @@
}
}
}
+
+ /**
+ * Creates a device admin info object for the resolved intent that points to the component of
+ * the device admin.
+ *
+ * @param ai ActivityInfo for the admin component.
+ * @return new {@link DeviceAdminInfo} object or null if there was an error.
+ */
+ private static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
+ try {
+ return new DeviceAdminInfo(context, ai);
+ } catch (XmlPullParserException | IOException e) {
+ Log.w(TAG, "Skipping " + ai, e);
+ }
+ return null;
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java
deleted file mode 100644
index 13d9d20..0000000
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.applications.specialaccess.deviceadmin;
-
-import android.app.admin.DeviceAdminInfo;
-import android.content.Context;
-import android.content.pm.ActivityInfo;
-import android.os.UserHandle;
-import android.util.Log;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.IOException;
-
-public class DeviceAdminUtils {
-
- private static final String TAG = "DeviceAdminUtils";
-
- /**
- * Creates a device admin info object for the resolved intent that points to the component of
- * the device admin.
- *
- * @param ai ActivityInfo for the admin component.
- * @return new {@link DeviceAdminInfo} object or null if there was an error.
- */
- public static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
- try {
- return new DeviceAdminInfo(context, ai);
- } catch (XmlPullParserException | IOException e) {
- Log.w(TAG, "Skipping " + ai, e);
- }
- return null;
- }
-
- /**
- * Extracts the user id from a device admin info object.
- *
- * @param adminInfo the device administrator info.
- * @return identifier of the user associated with the device admin.
- */
- public static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
- return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
- }
-}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java
index 4485c53..01cd5f3 100644
--- a/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java
@@ -21,6 +21,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
public class SerialNumberPreferenceController extends BasePreferenceController {
@@ -40,6 +41,17 @@
}
@Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
+ public void copy() {
+ Sliceable.setCopyContent(mContext, getSummary(),
+ mContext.getText(R.string.status_serial_number));
+ }
+
+ @Override
public CharSequence getSummary() {
return Build.getSerial();
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
index a0449f2..153aa40 100644
--- a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
+++ b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
@@ -65,6 +65,11 @@
AnomalyType.EXCESSIVE_CRASH_RATE,
AnomalyType.EXCESSIVE_CRASH_LOOPING,
AnomalyType.NUMBER_OF_OPEN_FILES,
+ AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CONTACT_ACCESS,
+ AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND,
+ AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP,
})
public @interface AnomalyType {
/**
@@ -218,6 +223,42 @@
* The application crashed because no more file descriptors were available.
*/
int NUMBER_OF_OPEN_FILES = 26;
+
+ /**
+ * The application used an excessive amount of CPU while in a
+ * background process state.
+ */
+ int EXCESSIVE_CPU_USAGE_IN_BACKGROUND = 27;
+
+ /**
+ * The application kept the camera open for an excessive amount
+ * of time while in a bckground process state.
+ */
+ int EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND = 28;
+
+ /**
+ * The application has accessed the contacts content provider an
+ * excessive amount.
+ */
+ int EXCESSIVE_CONTACT_ACCESS = 29;
+
+ /**
+ * The application has played too much audio while in a background
+ * process state.
+ */
+ int EXCESSIVE_AUDIO_IN_BACKGROUND = 30;
+
+ /**
+ * The application has crashed or ANRed too many times while in a
+ * background process state.
+ */
+ int EXCESSIVE_CRASH_ANR_IN_BACKGROUND = 31;
+
+ /**
+ * An application which has not been used by the user recently
+ * was detected to cause an excessive amount of battery drain.
+ */
+ int BATTERY_DRAIN_FROM_UNUSED_APP = 32;
}
}
diff --git a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
index 35ff2ec..e21bb75 100644
--- a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
@@ -61,6 +61,17 @@
LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref != null) {
mSettingObserver = new SettingObserver(pref);
+ pref.setOnPreferenceClickListener(preference -> {
+ int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.VOLUME_HUSH_GESTURE,
+ Settings.Secure.VOLUME_HUSH_VIBRATE);
+ boolean isChecked = preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.VOLUME_HUSH_GESTURE, isChecked
+ ? Settings.Secure.VOLUME_HUSH_OFF
+ : Settings.Secure.VOLUME_HUSH_VIBRATE);
+ return true;
+ });
mSwitch = pref.findViewById(R.id.switch_bar);
if (mSwitch != null) {
mSwitch.addOnSwitchChangeListener(this);
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
index 42e18ed..d6ea6ca 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
+import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.text.format.DateUtils;
diff --git a/src/com/android/settings/nfc/NfcPreferenceController.java b/src/com/android/settings/nfc/NfcPreferenceController.java
index 04f288d..2ca3b23 100644
--- a/src/com/android/settings/nfc/NfcPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcPreferenceController.java
@@ -15,20 +15,26 @@
*/
package com.android.settings.nfc;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
import android.content.IntentFilter;
+import android.net.Uri;
import android.nfc.NfcAdapter;
import android.provider.Settings;
-
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import java.io.IOException;
+
public class NfcPreferenceController extends TogglePreferenceController
implements LifecycleObserver, OnResume, OnPause {
@@ -51,8 +57,7 @@
return;
}
- final SwitchPreference switchPreference =
- (SwitchPreference) screen.findPreference(getPreferenceKey());
+ final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
mNfcEnabler = new NfcEnabler(mContext, switchPreference);
@@ -87,14 +92,6 @@
}
@Override
- public IntentFilter getIntentFilter() {
- final IntentFilter filter = new IntentFilter();
- filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
- filter.addAction(NfcAdapter.EXTRA_ADAPTER_STATE);
- return filter;
- }
-
- @Override
public boolean hasAsyncUpdate() {
return true;
}
@@ -105,6 +102,11 @@
}
@Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return NfcSliceWorker.class;
+ }
+
+ @Override
public void onResume() {
if (mAirplaneModeObserver != null) {
mAirplaneModeObserver.register();
@@ -135,4 +137,77 @@
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
return toggleable != null && toggleable.contains(Settings.Global.RADIO_NFC);
}
+
+ /**
+ * Listener for background changes to NFC.
+ *
+ * <p>
+ * Listen to broadcasts from {@link NfcAdapter}. The worker will call notify changed on the
+ * NFC Slice only when the following extras are present in the broadcast:
+ * <ul>
+ * <li>{@link NfcAdapter#STATE_ON}</li>
+ * <li>{@link NfcAdapter#STATE_OFF}</li>
+ * </ul>
+ */
+ public static class NfcSliceWorker extends SliceBackgroundWorker<Void> {
+
+ private static final String TAG = "NfcSliceWorker";
+
+ private static final IntentFilter NFC_FILTER =
+ new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+
+ private NfcUpdateReceiver mUpdateObserver;
+
+ public NfcSliceWorker(Context context, Uri uri) {
+ super(context, uri);
+ mUpdateObserver = new NfcUpdateReceiver(this);
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ getContext().registerReceiver(mUpdateObserver, NFC_FILTER);
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ getContext().unregisterReceiver(mUpdateObserver);
+ }
+
+ @Override
+ public void close() throws IOException {
+ mUpdateObserver = null;
+ }
+
+ public void updateSlice() {
+ notifySliceChange();
+ }
+
+ public class NfcUpdateReceiver extends BroadcastReceiver {
+
+ private final int NO_EXTRA = -1;
+
+ private final NfcSliceWorker mSliceBackgroundWorker;
+
+ public NfcUpdateReceiver(NfcSliceWorker sliceWorker) {
+ mSliceBackgroundWorker = sliceWorker;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final int nfcStateExtra = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
+ NO_EXTRA);
+
+ // Do nothing if state change is empty, or an intermediate step.
+ if ( (nfcStateExtra == NO_EXTRA)
+ || (nfcStateExtra == NfcAdapter.STATE_TURNING_ON)
+ || (nfcStateExtra == NfcAdapter.STATE_TURNING_OFF)) {
+ Log.d(TAG, "Transitional update, dropping broadcast");
+ return;
+ }
+
+ Log.d(TAG, "Nfc broadcast received, updating Slice.");
+ mSliceBackgroundWorker.updateSlice();
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
index 5c591b8..66f27fe 100644
--- a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
@@ -16,18 +16,46 @@
package com.android.settings.notification;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserHandle;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.applications.DefaultAppInfo;
+import com.android.settingslib.widget.CandidateInfo;
+
+import com.google.common.annotations.VisibleForTesting;
public class NotificationAssistantPreferenceController extends BasePreferenceController {
+ @VisibleForTesting
+ protected NotificationBackend mNotificationBackend;
+ private PackageManager mPackageManager;
+
public NotificationAssistantPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mNotificationBackend = new NotificationBackend();
+ mPackageManager = mContext.getPackageManager();
}
@Override
public int getAvailabilityStatus() {
return BasePreferenceController.AVAILABLE;
}
+
+ @Override
+ public CharSequence getSummary() {
+ CandidateInfo appSelected = new NotificationAssistantPicker.CandidateNone(mContext);
+ ComponentName assistant = mNotificationBackend.getAllowedNotificationAssistant();
+ if (assistant != null) {
+ appSelected = createCandidateInfo(assistant);
+ }
+ return appSelected.loadLabel();
+ }
+
+ @VisibleForTesting
+ protected CandidateInfo createCandidateInfo(ComponentName cn) {
+ return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(), cn);
+ }
}
diff --git a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
index 7b37855..733d0d9 100644
--- a/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
+++ b/src/com/android/settings/notification/RingtonePreferenceControllerBase.java
@@ -50,13 +50,18 @@
}
private void updateSummary(Preference preference) {
- Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(mContext, getRingtoneType());
- final CharSequence summary = Ringtone.getTitle(
- mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
+ final Uri ringtoneUri = RingtoneManager.getActualDefaultRingtoneUri(
+ mContext, getRingtoneType());
+
+ final CharSequence summary;
+ if (ringtoneUri == null) {
+ summary = null;
+ } else {
+ summary = Ringtone.getTitle(
+ mContext, ringtoneUri, false /* followSettingsUri */, true /* allowRemote */);
+ }
if (summary != null) {
- ThreadUtils.postOnMainThread(() -> {
- preference.setSummary(summary);
- });
+ ThreadUtils.postOnMainThread(() -> preference.setSummary(summary));
}
}
diff --git a/src/com/android/settings/slices/CustomSliceable.java b/src/com/android/settings/slices/CustomSliceable.java
index b48f22a..0b97bed 100644
--- a/src/com/android/settings/slices/CustomSliceable.java
+++ b/src/com/android/settings/slices/CustomSliceable.java
@@ -84,18 +84,6 @@
Intent getIntent();
/**
- * Settings Slices which require background work, such as updating lists should implement a
- * {@link SliceBackgroundWorker} and return it here. An example of background work is updating
- * a list of Wifi networks available in the area.
- *
- * @return a {@link Class<? extends SliceBackgroundWorker>} to perform background work for the
- * slice.
- */
- default Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
- return null;
- }
-
- /**
* Standardize the intents returned to indicate actions by the Slice.
* <p>
* The {@link PendingIntent} is linked to {@link SliceBroadcastReceiver} where the Intent
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 5c662e5..397b2fc 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -153,7 +153,7 @@
if (filter != null) {
registerIntentToUri(filter, sliceUri);
}
- ThreadUtils.postOnMainThread(() -> startBackgroundWorker(sliceable));
+ ThreadUtils.postOnMainThread(() -> startBackgroundWorker(sliceable, sliceUri));
return;
}
@@ -326,20 +326,19 @@
}
}
- private void startBackgroundWorker(CustomSliceable sliceable) {
+ private void startBackgroundWorker(Sliceable sliceable, Uri uri) {
final Class workerClass = sliceable.getBackgroundWorkerClass();
if (workerClass == null) {
return;
}
- final Uri uri = sliceable.getUri();
if (mPinnedWorkers.containsKey(uri)) {
return;
}
Log.d(TAG, "Starting background worker for: " + uri);
final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(
- getContext(), sliceable);
+ getContext(), sliceable, uri);
mPinnedWorkers.put(uri, worker);
worker.onSlicePinned();
}
@@ -397,6 +396,8 @@
registerIntentToUri(filter, uri);
}
+ ThreadUtils.postOnMainThread(() -> startBackgroundWorker(controller, uri));
+
final List<Uri> pinnedSlices = getContext().getSystemService(
SliceManager.class).getPinnedSlices();
if (pinnedSlices.contains(uri)) {
diff --git a/src/com/android/settings/slices/SliceBackgroundWorker.java b/src/com/android/settings/slices/SliceBackgroundWorker.java
index 995394e..559aa71 100644
--- a/src/com/android/settings/slices/SliceBackgroundWorker.java
+++ b/src/com/android/settings/slices/SliceBackgroundWorker.java
@@ -80,13 +80,12 @@
* Returns the singleton instance of the {@link SliceBackgroundWorker} for specified {@link
* CustomSliceable}
*/
- static SliceBackgroundWorker getInstance(Context context, CustomSliceable sliceable) {
- final Uri uri = sliceable.getUri();
+ static SliceBackgroundWorker getInstance(Context context, Sliceable sliceable, Uri uri) {
SliceBackgroundWorker worker = getInstance(uri);
if (worker == null) {
final Class<? extends SliceBackgroundWorker> workerClass =
sliceable.getBackgroundWorkerClass();
- worker = createInstance(context, uri, workerClass);
+ worker = createInstance(context.getApplicationContext(), uri, workerClass);
LIVE_WORKERS.put(uri, worker);
}
return worker;
diff --git a/src/com/android/settings/slices/SliceBroadcastReceiver.java b/src/com/android/settings/slices/SliceBroadcastReceiver.java
index 2a9b491..b2ea583 100644
--- a/src/com/android/settings/slices/SliceBroadcastReceiver.java
+++ b/src/com/android/settings/slices/SliceBroadcastReceiver.java
@@ -197,7 +197,7 @@
return;
}
- ((Sliceable) controller).copy();
+ controller.copy();
}
/**
diff --git a/src/com/android/settings/slices/Sliceable.java b/src/com/android/settings/slices/Sliceable.java
index b00ab82..c1661f8 100644
--- a/src/com/android/settings/slices/Sliceable.java
+++ b/src/com/android/settings/slices/Sliceable.java
@@ -91,4 +91,16 @@
final String toast = context.getString(R.string.copyable_slice_toast, messageTitle);
Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
}
+
+ /**
+ * Settings Slices which require background work, such as updating lists should implement a
+ * {@link SliceBackgroundWorker} and return it here. An example of background work is updating
+ * a list of Wifi networks available in the area.
+ *
+ * @return a {@link Class<? extends SliceBackgroundWorker>} to perform background work for the
+ * slice.
+ */
+ default Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return null;
+ }
}
diff --git a/src/com/android/settings/slices/SlicesIndexer.java b/src/com/android/settings/slices/SlicesIndexer.java
index ec2be29..1b3a25e 100644
--- a/src/com/android/settings/slices/SlicesIndexer.java
+++ b/src/com/android/settings/slices/SlicesIndexer.java
@@ -71,7 +71,7 @@
long startTime = System.currentTimeMillis();
database.beginTransaction();
try {
- mHelper.reconstruct(mHelper.getWritableDatabase());
+ mHelper.reconstruct(database);
List<SliceData> indexData = getSliceData();
insertSliceData(database, indexData);
diff --git a/src/com/android/settings/wifi/AddNetworkFragment.java b/src/com/android/settings/wifi/AddNetworkFragment.java
index 651b25f..81b6c85 100644
--- a/src/com/android/settings/wifi/AddNetworkFragment.java
+++ b/src/com/android/settings/wifi/AddNetworkFragment.java
@@ -19,12 +19,14 @@
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Intent;
+import android.net.wifi.WifiConfiguration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
+import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -40,7 +42,10 @@
final static int SUBMIT_BUTTON_ID = android.R.id.button1;
@VisibleForTesting
final static int CANCEL_BUTTON_ID = android.R.id.button2;
- final static int SCANNER_BUTTON_ID = R.id.ssid_scanner_button;
+ final static int SSID_SCANNER_BUTTON_ID = R.id.ssid_scanner_button;
+ final static int PASSWORD_SCANNER_BUTTON_ID = R.id.password_scanner_button;
+
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
private WifiConfigController mUIController;
private Button mSubmitBtn;
@@ -68,10 +73,12 @@
mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID);
mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID);
- final ImageButton scannerButton = rootView.findViewById(SCANNER_BUTTON_ID);
+ final ImageButton ssidScannerButton = rootView.findViewById(SSID_SCANNER_BUTTON_ID);
+ final ImageButton passwordScannerButton = rootView.findViewById(PASSWORD_SCANNER_BUTTON_ID);
mSubmitBtn.setOnClickListener(this);
mCancelBtn.setOnClickListener(this);
- scannerButton.setOnClickListener(this);
+ ssidScannerButton.setOnClickListener(this);
+ passwordScannerButton.setOnClickListener(this);
mUIController = new WifiConfigController(this, rootView, null, getMode());
return rootView;
@@ -85,6 +92,8 @@
@Override
public void onClick(View view) {
+ String ssid = null;
+
switch (view.getId()) {
case SUBMIT_BUTTON_ID:
handleSubmitAction();
@@ -92,15 +101,34 @@
case CANCEL_BUTTON_ID:
handleCancelAction();
break;
- case SCANNER_BUTTON_ID:
+ case SSID_SCANNER_BUTTON_ID:
+ final TextView ssidEditText = getView().findViewById(R.id.ssid);
+ ssid = ssidEditText.getText().toString();
+ // No break and flows to case PASSWORD_SCANNER_BUTTON_ID
+ case PASSWORD_SCANNER_BUTTON_ID:
// Launch QR code scanner to join a network.
- getContext().startActivity(
- WifiDppUtils.getEnrolleeQrCodeScannerIntent(/* ssid */ null));
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
break;
}
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode != Activity.RESULT_OK) {
+ return;
+ }
+
+ final WifiConfiguration config = data.getParcelableExtra(
+ WifiDialogActivity.KEY_WIFI_CONFIGURATION);
+ successfullyFinish(config);
+ }
+ }
+
+ @Override
public int getMode() {
return WifiConfigUiBase.MODE_CONNECT;
}
@@ -158,9 +186,13 @@
@VisibleForTesting
void handleSubmitAction() {
+ successfullyFinish(mUIController.getConfig());
+ }
+
+ private void successfullyFinish(WifiConfiguration config) {
final Intent intent = new Intent();
final Activity activity = getActivity();
- intent.putExtra(WIFI_CONFIG_KEY, mUIController.getConfig());
+ intent.putExtra(WIFI_CONFIG_KEY, config);
activity.setResult(Activity.RESULT_OK, intent);
activity.finish();
}
diff --git a/src/com/android/settings/wifi/WifiDialog.java b/src/com/android/settings/wifi/WifiDialog.java
index 7d5f3b3..fbea824 100644
--- a/src/com/android/settings/wifi/WifiDialog.java
+++ b/src/com/android/settings/wifi/WifiDialog.java
@@ -18,15 +18,16 @@
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
+import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
-import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.wifi.AccessPoint;
@@ -40,6 +41,9 @@
default void onSubmit(WifiDialog dialog) {
}
+
+ default void onScan(WifiDialog dialog, String ssid) {
+ }
}
private static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
@@ -80,18 +84,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null);
- final ImageButton scannerButton = mView.findViewById(R.id.password_scanner_button);
- if (scannerButton != null) {
- scannerButton.setOnClickListener((View v) -> {
- String ssid = null;
- if (mAccessPoint != null) {
- ssid = mAccessPoint.getSsidStr();
- }
- // Launch QR code scanner to join a network.
- getContext().startActivity(
- WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid));
- });
- }
setView(mView);
mController = new WifiConfigController(this, mView, mAccessPoint, mMode);
super.onCreate(savedInstanceState);
@@ -109,6 +101,35 @@
}
}
+ @Override
+ protected void onStart() {
+ View.OnClickListener onClickScannerButtonListener = v -> {
+ if (mListener == null) {
+ return;
+ }
+
+ String ssid = null;
+ if (mAccessPoint == null) {
+ final TextView ssidEditText = findViewById(R.id.ssid);
+ ssid = ssidEditText.getText().toString();
+ } else {
+ ssid = mAccessPoint.getSsidStr();
+ }
+ mListener.onScan(/* WifiDialog */ this, ssid);
+ };
+
+ final ImageButton ssidScannerButton = findViewById(R.id.ssid_scanner_button);
+ ssidScannerButton.setOnClickListener(onClickScannerButtonListener);
+
+ final ImageButton passwordScannerButton = findViewById(R.id.password_scanner_button);
+ passwordScannerButton.setOnClickListener(onClickScannerButtonListener);
+
+ if (mHideSubmitButton) {
+ ssidScannerButton.setVisibility(View.GONE);
+ passwordScannerButton.setVisibility(View.GONE);
+ }
+ }
+
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mController.updatePassword();
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index c32bcf3..35de66e 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -29,6 +29,7 @@
import androidx.annotation.VisibleForTesting;
import com.android.settings.SetupWizardUtils;
+import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -49,10 +50,13 @@
@VisibleForTesting
static final String KEY_CONNECT_FOR_CALLER = "connect_for_caller";
- private static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
+ public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
+
private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
+
private WifiDialog mDialog;
@Override
@@ -162,4 +166,25 @@
mDialog = null;
finish();
}
+
+ @Override
+ public void onScan(WifiDialog dialog, String ssid) {
+ // Launch QR code scanner to join a network.
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode != RESULT_OK) {
+ return;
+ }
+
+ setResult(RESULT_CONNECTED, data);
+ finish();
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 4ca9f86..27c495e 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -117,6 +117,8 @@
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
private static final String PREF_KEY_STATUS_MESSAGE = "wifi_status_message";
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
+
private static boolean isVerboseLoggingEnabled() {
return WifiTracker.sVerboseLogging || Log.isLoggable(TAG, Log.VERBOSE);
}
@@ -427,10 +429,17 @@
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- // Only handle request comes from AddNetworkFragment
if (requestCode == ADD_NETWORK_REQUEST) {
handleAddNetworkRequest(resultCode, data);
return;
+ } else if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode == Activity.RESULT_OK) {
+ if (mDialog != null) {
+ mDialog.dismiss();
+ }
+ mWifiTracker.resumeScanning();
+ }
+ return;
}
final boolean formerlyRestricted = mIsRestricted;
@@ -1065,6 +1074,13 @@
}
}
+ @Override
+ public void onScan(WifiDialog dialog, String ssid) {
+ // Launch QR code scanner to join a network.
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
+ }
+
/* package */ void submit(WifiConfigController configController) {
final WifiConfiguration config = configController.getConfig();
diff --git a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
index 97b2ebe..9e731ba 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
@@ -172,6 +172,9 @@
mLatestStatusCode = code;
}
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
+ }
mProgressBar.setVisibility(isGoingInitiator() ? View.VISIBLE : View.INVISIBLE);
mButtonRight.setVisibility(isGoingInitiator() ? View.INVISIBLE : View.VISIBLE);
}
@@ -255,7 +258,7 @@
mTitle.setText(information);
}
- mSummary.setText(getString(R.string.wifi_dpp_add_device_to_wifi, getSsid()));
+ updateSummary();
mWifiApPictureView = view.findViewById(R.id.wifi_ap_picture_view);
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
@@ -273,6 +276,7 @@
mProgressBar.setVisibility(View.VISIBLE);
mButtonRight.setVisibility(View.INVISIBLE);
startWifiDppConfiguratorInitiator();
+ updateSummary();
});
if (savedInstanceState != null) {
@@ -342,4 +346,12 @@
return model.isGoingInitiator();
}
+
+ private void updateSummary() {
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
+ } else {
+ mSummary.setText(getString(R.string.wifi_dpp_add_device_to_wifi, getSsid()));
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index e664a05..a19069b 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -31,7 +31,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.Size;
@@ -48,6 +47,7 @@
import androidx.lifecycle.ViewModelProviders;
import com.android.settings.R;
+import com.android.settings.wifi.WifiDialogActivity;
import com.android.settings.wifi.qrcode.QrCamera;
import com.android.settings.wifi.qrcode.QrDecorateView;
@@ -77,6 +77,7 @@
// Key for Bundle usage
private static final String KEY_IS_CONFIGURATOR_MODE = "key_is_configurator_mode";
private static final String KEY_LATEST_ERROR_CODE = "key_latest_error_code";
+ private static final String KEY_WIFI_CONFIGURATION = "key_wifi_configuration";
private ProgressBar mProgressBar;
private QrCamera mCamera;
@@ -93,6 +94,9 @@
/** QR code data scanned by camera */
private WifiQrCode mWifiQrCode;
+ /** The WifiConfiguration connecting for enrollee usage */
+ private WifiConfiguration mWifiConfiguration;
+
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
@Override
@@ -102,6 +106,7 @@
if (savedInstanceState != null) {
mIsConfiguratorMode = savedInstanceState.getBoolean(KEY_IS_CONFIGURATOR_MODE);
mLatestStatusCode = savedInstanceState.getInt(KEY_LATEST_ERROR_CODE);
+ mWifiConfiguration = savedInstanceState.getParcelable(KEY_WIFI_CONFIGURATION);
}
final WifiDppInitiatorViewModel model =
@@ -224,13 +229,7 @@
} else {
mTitle.setText(R.string.wifi_dpp_scan_qr_code);
- String description;
- if (TextUtils.isEmpty(mSsid)) {
- description = getString(R.string.wifi_dpp_scan_qr_code_join_unknown_network, mSsid);
- } else {
- description = getString(R.string.wifi_dpp_scan_qr_code_join_network, mSsid);
- }
- mSummary.setText(description);
+ updateEnrolleeSummary();
}
mErrorMessage = view.findViewById(R.id.error_message);
@@ -410,6 +409,7 @@
if (!mIsConfiguratorMode) {
mProgressBar.setVisibility(View.VISIBLE);
startWifiDppEnrolleeInitiator((WifiQrCode)msg.obj);
+ updateEnrolleeSummary();
}
break;
@@ -417,6 +417,7 @@
mErrorMessage.setVisibility(View.INVISIBLE);
final WifiNetworkConfig wifiNetworkConfig = (WifiNetworkConfig)msg.obj;
+ mWifiConfiguration = wifiNetworkConfig.getWifiConfigurationOrNull();
wifiNetworkConfig.connect(getContext(),
/* listener */ WifiDppQrCodeScannerFragment.this);
break;
@@ -431,6 +432,7 @@
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_IS_CONFIGURATOR_MODE, mIsConfiguratorMode);
outState.putInt(KEY_LATEST_ERROR_CODE, mLatestStatusCode);
+ outState.putParcelable(KEY_WIFI_CONFIGURATION, mWifiConfiguration);
super.onSaveInstanceState(outState);
}
@@ -446,6 +448,7 @@
for (WifiConfiguration wifiConfig : wifiConfigs) {
if (wifiConfig.networkId == newNetworkId) {
mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_SUCCESS;
+ mWifiConfiguration = wifiConfig;
wifiManager.connect(wifiConfig, WifiDppQrCodeScannerFragment.this);
return;
}
@@ -453,6 +456,7 @@
Log.e(TAG, "Invalid networkId " + newNetworkId);
mLatestStatusCode = EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_GENERIC;
+ updateEnrolleeSummary();
mProgressBar.setVisibility(View.INVISIBLE);
showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
restartCamera();
@@ -520,6 +524,7 @@
}
mLatestStatusCode = code;
+ updateEnrolleeSummary();
mProgressBar.setVisibility(View.INVISIBLE);
restartCamera();
}
@@ -539,9 +544,11 @@
@Override
public void onSuccess() {
- startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+ final Intent resultIntent = new Intent();
+ resultIntent.putExtra(WifiDialogActivity.KEY_WIFI_CONFIGURATION, mWifiConfiguration);
+
final Activity hostActivity = getActivity();
- hostActivity.setResult(Activity.RESULT_OK);
+ hostActivity.setResult(Activity.RESULT_OK, resultIntent);
hostActivity.finish();
}
@@ -578,4 +585,18 @@
mCamera.start(surfaceTexture);
}
+
+ private void updateEnrolleeSummary() {
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_connecting);
+ } else {
+ String description;
+ if (TextUtils.isEmpty(mSsid)) {
+ description = getString(R.string.wifi_dpp_scan_qr_code_join_unknown_network, mSsid);
+ } else {
+ description = getString(R.string.wifi_dpp_scan_qr_code_join_network, mSsid);
+ }
+ mSummary.setText(description);
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
index 24cd1d7..6c991cf 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
@@ -95,6 +95,11 @@
/**
* Returns an intent to launch QR code scanner for Wi-Fi DPP enrollee.
*
+ * After enrollee success, the callee activity will return connecting WifiConfiguration by
+ * putExtra {@code WifiDialogActivity.KEY_WIFI_CONFIGURATION} for
+ * {@code Activity#setResult(int resultCode, Intent data)}. The calling object should check
+ * if it's available before using it.
+ *
* @param ssid The data corresponding to {@code WifiConfiguration} SSID
* @return Intent for launching QR code scanner
*/
diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
index 979e602..6135cba 100644
--- a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
+++ b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
@@ -228,7 +228,7 @@
/**
* This is a simplified method from {@code WifiConfigController.getConfig()}
*/
- private WifiConfiguration getWifiConfigurationOrNull() {
+ WifiConfiguration getWifiConfigurationOrNull() {
if (!isValidConfig(this)) {
return null;
}
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
index 96d5bf5..8c53019 100644
--- a/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilitySettingsTest.java
@@ -21,14 +21,17 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
+import android.app.UiModeManager;
import android.content.ContentResolver;
import android.content.Context;
import android.os.Vibrator;
import android.provider.Settings;
+import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.display.DarkUIPreferenceController;
import com.android.settings.testutils.XmlTestUtils;
import org.junit.Before;
@@ -47,10 +50,13 @@
"accessibility_content_timeout_preference_fragment";
private static final String ACCESSIBILITY_CONTROL_TIMEOUT_PREFERENCE =
"accessibility_control_timeout_preference_fragment";
+ private static final String DARK_UI_MODE_PREFERENCE =
+ "dark_ui_mode_accessibility";
private Context mContext;
private ContentResolver mContentResolver;
private AccessibilitySettings mSettings;
+ private UiModeManager mUiModeManager;
@Before
public void setup() {
@@ -59,6 +65,7 @@
mContentResolver = mContext.getContentResolver();
mSettings = spy(new AccessibilitySettings());
doReturn(mContext).when(mSettings).getContext();
+ mUiModeManager = mContext.getSystemService(UiModeManager.class);
}
@Test
@@ -146,4 +153,29 @@
assertThat(preference.getSummary()).isEqualTo(mContext.getResources().getString(resId));
}
+
+ @Test
+ public void testDarkUIModePreferenceSummary_shouldUpdateSummary() {
+ final ListPreference darkUIModePreference = new ListPreference(mContext);
+ final DarkUIPreferenceController mController;
+ doReturn(darkUIModePreference).when(mSettings).findPreference(
+ DARK_UI_MODE_PREFERENCE);
+ mController = new DarkUIPreferenceController(mContext, DARK_UI_MODE_PREFERENCE);
+ final String darkUIModeDescription = modeToDescription(mUiModeManager.getNightMode());
+ darkUIModePreference.setSummary(mController.getSummary());
+
+ assertThat(darkUIModePreference.getSummary()).isEqualTo(darkUIModeDescription);
+ }
+
+ private String modeToDescription(int mode) {
+ String[] values = mContext.getResources().getStringArray(R.array.dark_ui_mode_entries);
+ switch (mode) {
+ case UiModeManager.MODE_NIGHT_YES:
+ return values[0];
+ case UiModeManager.MODE_NIGHT_NO:
+ case UiModeManager.MODE_NIGHT_AUTO:
+ default:
+ return values[1];
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java
new file mode 100644
index 0000000..ec3cf65
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/applications/AllAppsInfoPreferenceControllerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.applications;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.usage.UsageStats;
+import android.content.Context;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+public class AllAppsInfoPreferenceControllerTest {
+
+ private AllAppsInfoPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ final Context context = RuntimeEnvironment.application;
+ mController = new AllAppsInfoPreferenceController(context, "test_key");
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasRecentApps_shouldReturnConditionallyUnavailable() {
+ final List<UsageStats> stats = new ArrayList<>();
+ final UsageStats stat1 = new UsageStats();
+ stat1.mLastTimeUsed = System.currentTimeMillis();
+ stat1.mPackageName = "pkg.class";
+ stats.add(stat1);
+ mController.setRecentApps(stats);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noRecentApps_shouldReturnAvailable() {
+ // No data
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
index 1411bc0..1a28f37 100644
--- a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
import static com.google.common.truth.Truth.assertThat;
@@ -25,9 +26,9 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -111,7 +112,6 @@
final View appEntitiesHeaderView = LayoutInflater.from(context).inflate(
R.layout.app_entities_header, null /* root */);
- final Preference seeAllPreference = new Preference(context);
final Preference dividerPreference = new Preference(context);
mRecentAppsPreference = spy(new LayoutPreference(context, appEntitiesHeaderView));
@@ -119,11 +119,8 @@
mController.setFragment(mFragment);
mController.mAppEntitiesController = mock(AppEntitiesHeaderController.class);
mController.mRecentAppsPreference = mRecentAppsPreference;
- mController.mAllAppPref = seeAllPreference;
mController.mDivider = dividerPreference;
- when(mScreen.findPreference(RecentAppsPreferenceController.KEY_ALL_APP_INFO))
- .thenReturn(seeAllPreference);
when(mScreen.findPreference(RecentAppsPreferenceController.KEY_DIVIDER))
.thenReturn(dividerPreference);
when(mScreen.findPreference("test_key")).thenReturn(mRecentAppsPreference);
@@ -146,24 +143,53 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.reloadData();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
- public void getAvailabilityStatus_noRecentApps_shouldReturnAvailableUnsearchable() {
+ public void getAvailabilityStatus_noRecentApps_shouldReturnConditionallyUnavailable() {
// No data
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
- public void displayPreferenceAndUpdateState_shouldRefreshUi() {
- doNothing().when(mController).refreshUi();
+ public void getAvailabilityStatus_powerSaverModeOn_shouldReturnConditionallyUnavailable() {
+ when(mPowerManager.isPowerSaveMode()).thenReturn(true);
+ final List<UsageStats> stats = new ArrayList<>();
+ final UsageStats stat1 = new UsageStats();
+
+ stat1.mLastTimeUsed = System.currentTimeMillis();
+ stat1.mPackageName = "pkg.class";
+ stats.add(stat1);
+
+ // stat1, stat2 are valid apps. stat3 is invalid.
+ when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
+ .thenReturn(mAppEntry);
+ when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
+ .thenReturn(new ResolveInfo());
+ when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
+ .thenReturn(stats);
+ mAppEntry.info = mApplicationInfo;
+ mController.reloadData();
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void displayPreference_shouldNotReloadData() {
mController.displayPreference(mScreen);
- mController.updateState(mScreen);
- verify(mController, times(2)).refreshUi();
+ verify(mController, never()).reloadData();
+ }
+
+ @Test
+ public void displayPreference_shouldRefreshUi() {
+ mController.displayPreference(mScreen);
+
+ verify(mController).refreshUi();
}
@Test
@@ -203,6 +229,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.reloadData();
mController.updateState(mRecentAppsPreference);
@@ -210,7 +237,6 @@
.setAppEntity(anyInt(), any(AppEntityInfo.class));
assertThat(mController.mRecentAppsPreference.isVisible()).isTrue();
assertThat(mController.mDivider.isVisible()).isTrue();
- assertThat(mController.mAllAppPref.isVisible()).isFalse();
}
@Test
@@ -243,6 +269,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.reloadData();
mController.updateState(mRecentAppsPreference);
@@ -252,34 +279,6 @@
.setAppEntity(anyInt(), any(AppEntityInfo.class));
assertThat(mController.mRecentAppsPreference.isVisible()).isTrue();
assertThat(mController.mDivider.isVisible()).isTrue();
- assertThat(mController.mAllAppPref.isVisible()).isFalse();
- }
-
- @Test
- public void updateState_powerSaverModeOn_headerIsNotVisible() {
- when(mPowerManager.isPowerSaveMode()).thenReturn(true);
-
- final List<UsageStats> stats = new ArrayList<>();
- final UsageStats stat1 = new UsageStats();
-
- stat1.mLastTimeUsed = System.currentTimeMillis();
- stat1.mPackageName = "pkg.class";
- stats.add(stat1);
-
- // stat1, stat2 are valid apps. stat3 is invalid.
- when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
- .thenReturn(mAppEntry);
- when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(new ResolveInfo());
- when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
- .thenReturn(stats);
- mAppEntry.info = mApplicationInfo;
-
- mController.updateState(mRecentAppsPreference);
-
- assertThat(mController.mRecentAppsPreference.isVisible()).isFalse();
- assertThat(mController.mDivider.isVisible()).isFalse();
- assertThat(mController.mAllAppPref.isVisible()).isTrue();
}
@Test
@@ -314,6 +313,7 @@
// Make sure stat2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (ApplicationInfo info) -> info == stat2Entry.info);
+ mController.reloadData();
mController.updateState(mRecentAppsPreference);
@@ -389,6 +389,7 @@
.thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
+ mController.reloadData();
mController.updateState(mRecentAppsPreference);
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
index 17703e3..7392fb1 100644
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
@@ -67,7 +67,7 @@
DeviceAdminListItem item = new DeviceAdminListItem(mContext, mDeviceAdminInfo);
- assertThat(item.getKey()).isEqualTo(cn.flattenToShortString());
+ assertThat(item.getKey()).isEqualTo("0@" + cn.flattenToShortString());
assertThat(item.getName()).isEqualTo(label);
assertThat(item.getDescription()).isEqualTo(description);
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java
new file mode 100644
index 0000000..c2ae4af
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.os.Build;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class SerialNumberPreferenceControllerTest {
+
+ private Context mContext;
+ private SerialNumberPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new SerialNumberPreferenceController(mContext, "test");
+ }
+
+ @Test
+ public void isCopyableSlice() {
+ assertThat(mController.isSliceable()).isTrue();
+ assertThat(mController.isCopyableSlice()).isTrue();
+ }
+
+ @Test
+ public void copy_shouldPutSerialNumberToClipBoard() {
+ mController.copy();
+
+ final ClipboardManager clipboardManager = mContext.getSystemService(ClipboardManager.class);
+ final ClipData data = clipboardManager.getPrimaryClip();
+
+ assertThat(data.getItemAt(0).getText().toString()).contains(Build.getSerial());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
index 5f221f5..85eeacc 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -29,8 +30,10 @@
import android.provider.Settings;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.widget.SwitchBar;
+import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
@@ -95,4 +98,16 @@
mController.updateState(mPreference);
verify(mController.mSwitch, times(1)).setChecked(true);
}
+
+ @Test
+ public void testPreferenceClickListenerAttached() {
+ PreferenceScreen preferenceScreen = mock(PreferenceScreen.class);
+ LayoutPreference mLayoutPreference = mock(LayoutPreference.class);
+ when(preferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mLayoutPreference);
+ mController.displayPreference(preferenceScreen);
+
+ verify(mLayoutPreference, times(1))
+ .setOnPreferenceClickListener(any());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
index 8883ddf..e3672c9 100644
--- a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
@@ -19,10 +19,13 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.os.UserManager;
@@ -31,6 +34,10 @@
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
+import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
+import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
+import com.android.settings.slices.SliceBuilderUtils;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -246,4 +253,67 @@
assertThat(mNfcController.mAirplaneModeObserver).isNull();
}
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_noExtra_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_turningOn_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_ON);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_turningOff_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_OFF);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_nfcOn_sliceUpdates() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_ON);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_nfcOff_sliceUpdates() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker).updateSlice();
+ }
+
+ private Uri getDummyUri() {
+ return SliceBuilderUtils.getUri("action/nfc", false);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
new file mode 100644
index 0000000..b2f65e0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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 junit.framework.TestCase.assertEquals;
+
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.Debug;
+
+import com.android.settingslib.widget.CandidateInfo;
+
+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;
+
+@RunWith(RobolectricTestRunner.class)
+public class NotificationAssistantPreferenceControllerTest {
+
+ private static final String KEY = "TEST_KEY";
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ private NotificationAssistantPreferenceController mPreferenceController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mPreferenceController = new TestPreferenceController(mContext, mBackend);
+ }
+
+ @Test
+ public void testGetSummary_noAssistant() {
+ when(mBackend.getAllowedNotificationAssistant()).thenReturn(null);
+ CharSequence noneLabel = new NotificationAssistantPicker.CandidateNone(mContext)
+ .loadLabel();
+ assertEquals(noneLabel, mPreferenceController.getSummary());
+ }
+
+ @Test
+ public void testGetSummary_TestAssistant() {
+ String testName = "test_pkg/test_cls";
+ when(mBackend.getAllowedNotificationAssistant()).thenReturn(
+ ComponentName.unflattenFromString(testName));
+ assertEquals(testName, mPreferenceController.getSummary());
+ }
+
+ private final class TestPreferenceController extends NotificationAssistantPreferenceController {
+
+ private TestPreferenceController(Context context, NotificationBackend backend) {
+ super(context, KEY);
+ mNotificationBackend = backend;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ protected CandidateInfo createCandidateInfo(ComponentName cn) {
+ return new CandidateInfo(true) {
+ @Override
+ public CharSequence loadLabel() { return cn.flattenToString(); }
+
+ @Override
+ public Drawable loadIcon() { return null; }
+
+ @Override
+ public String getKey() { return null; }
+ };
+ }
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
index f22a782..2fb1738 100644
--- a/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RingtonePreferenceControllerBaseTest.java
@@ -20,31 +20,31 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.media.RingtoneManager;
+import android.provider.Settings;
import androidx.preference.Preference;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class RingtonePreferenceControllerBaseTest {
- @Mock
private Context mContext;
private RingtonePreferenceControllerBase mController;
@Before
public void setUp() {
- MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
mController = new RingtonePreferenceControllerBaseTestable(mContext);
}
@@ -56,14 +56,26 @@
@Test
public void updateState_shouldSetSummary() {
Preference preference = mock(Preference.class);
+ Settings.System.putString(mContext.getContentResolver(), Settings.System.RINGTONE,
+ "content://test/ringtone");
mController.updateState(preference);
verify(preference).setSummary(anyString());
}
+ @Test
+ public void updateState_nullRingtone_shouldNotGetTitle() {
+ Preference preference = mock(Preference.class);
+ Settings.System.putString(mContext.getContentResolver(), Settings.System.RINGTONE, null);
+
+ mController.updateState(preference);
+
+ verify(preference, never()).setSummary(anyString());
+ }
+
private class RingtonePreferenceControllerBaseTestable
- extends RingtonePreferenceControllerBase {
+ extends RingtonePreferenceControllerBase {
RingtonePreferenceControllerBaseTestable(Context context) {
super(context);
}
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index 726e4bd..a693f34 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -64,6 +64,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -184,6 +185,20 @@
}
@Test
+ public void loadSlice_registersBackgroundListener() {
+ insertSpecialCase(KEY);
+ final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false);
+
+ mProvider.loadSlice(uri);
+
+ Robolectric.flushForegroundThreadScheduler();
+ Robolectric.flushBackgroundThreadScheduler();
+
+ assertThat(mProvider.mPinnedWorkers.get(uri).getClass())
+ .isEqualTo(FakeToggleController.TestWorker.class);
+ }
+
+ @Test
public void testLoadSlice_doesNotCacheWithoutPin() {
insertSpecialCase(KEY);
final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false);
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
index d1677cd..e785487 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
@@ -19,10 +19,14 @@
import android.content.Context;
import android.content.IntentFilter;
+import android.net.Uri;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.slices.SliceBackgroundWorker;
+
+import java.io.IOException;
public class FakeToggleController extends TogglePreferenceController {
@@ -71,6 +75,11 @@
}
@Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return TestWorker.class;
+ }
+
+ @Override
public boolean hasAsyncUpdate() {
return mIsAsyncUpdate;
}
@@ -78,4 +87,23 @@
public void setAsyncUpdate(boolean isAsyncUpdate) {
mIsAsyncUpdate = isAsyncUpdate;
}
+
+ public static class TestWorker extends SliceBackgroundWorker<Void> {
+
+ public TestWorker(Context context, Uri uri) {
+ super(context, uri);
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+ }
}
diff --git a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
index ede4631..19b1360 100644
--- a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
@@ -41,6 +41,7 @@
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.intent.Intents;
@@ -55,7 +56,9 @@
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
@@ -68,9 +71,14 @@
private NotificationChannel mUngroupedChannel;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
@@ -87,7 +95,8 @@
@Test
public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
@@ -99,60 +108,38 @@
@Test
public void launchNotificationSetting_showGroupsWithMultipleChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mGroup1.getName().toString()))).check(
matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup1Channel1.getName().toString())))
- .check(matches(isDisplayed()));
- fail("Channel erroneously appearing");
- } catch (Exception e) {
- // expected
- }
- // links to group page
- Intents.init();
- onView(allOf(withText(mGroup1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT,
- ChannelGroupNotificationSettings.class.getName())));
- Intents.release();
+ onView(allOf(withText(mGroup1Channel1.getName().toString()))).check(
+ matches(isDisplayed()));
+ onView(allOf(withText(mGroup1Channel2.getName().toString()))).check(
+ matches(isDisplayed()));
}
@Test
public void launchNotificationSetting_showUngroupedChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mUngroupedChannel.getName().toString())))
.check(matches(isDisplayed()));
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mUngroupedChannel.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
@Test
public void launchNotificationSetting_showGroupsWithOneChannel() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
+ onView(allOf(withText(mGroup2.getName().toString())))
+ .check(matches(isDisplayed()));
onView(allOf(withText(mGroup2Channel1.getName().toString())))
.check(matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup2.getName().toString()))).check(
- matches(isDisplayed()));
- fail("Group erroneously appearing");
- } catch (Exception e) {
- // expected
- }
-
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mGroup2Channel1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
private NotificationChannel createChannel(NotificationChannelGroup group,
diff --git a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
index f7a5a82..9a3a994 100644
--- a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
@@ -36,6 +36,7 @@
import android.os.Process;
import android.os.ServiceManager;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -48,17 +49,23 @@
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ChannelNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
private NotificationChannel mNotificationChannel;
private NotificationManager mNm;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationChannel = new NotificationChannel(this.getClass().getName(),
this.getClass().getName(), IMPORTANCE_MIN);
@@ -69,7 +76,8 @@
public void launchNotificationSetting_shouldNotCrash() {
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
@@ -90,12 +98,12 @@
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
- onView(allOf(withText("Off"), isDisplayed())).check(matches(isDisplayed()));
- onView(allOf(withText("Android is blocking this category of notifications from"
- + " appearing on this device"))).check(matches(isDisplayed()));
+ onView(allOf(withText("At your request, Android is blocking this category of notifications"
+ + " from appearing on this device"))).check(matches(isDisplayed()));
try {
onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
diff --git a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
index 2fe4074..4120a07 100644
--- a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
+++ b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
@@ -37,27 +37,29 @@
@Test
public void testZenModeSettingsPreferences() {
launchZenSettings();
- onView(withText("Behavior")).check(matches(isDisplayed()));
- onView(withText("Turn on automatically")).check(matches(isDisplayed()));
+ onView(withText("Calls")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeBehaviorPreferences() {
launchZenBehaviorSettings();
- onView(withText("Alarms")).check(matches(isDisplayed()));
- onView(withText("Media and system feedback")).check(matches(isDisplayed()));
- onView(withText("Reminders")).check(matches(isDisplayed()));
- onView(withText("Events")).check(matches(isDisplayed()));
- onView(withText("Messages")).check(matches(isDisplayed()));
onView(withText("Calls")).check(matches(isDisplayed()));
- onView(withText("Repeat callers")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeAutomationPreferences() {
launchZenAutomationSettings();
- onView(withText("Weekend")).check(matches(isDisplayed()));
- onView(withText("Add rule")).check(matches(isDisplayed()));
+ onView(withText("Sleeping")).check(matches(isDisplayed()));
+ onView(withText("Event")).check(matches(isDisplayed()));
+ onView(withText("Add more")).check(matches(isDisplayed()));
}
private void launchZenSettings() {