Merge "Import translations. DO NOT MERGE" into qt-dev
diff --git a/res/drawable-nodpi/gentle_notifications_shade.png b/res/drawable-nodpi/gentle_notifications_shade.png
new file mode 100644
index 0000000..dddef5c
--- /dev/null
+++ b/res/drawable-nodpi/gentle_notifications_shade.png
Binary files differ
diff --git a/res/drawable-nodpi/gentle_notifications_shade_lock.png b/res/drawable-nodpi/gentle_notifications_shade_lock.png
new file mode 100644
index 0000000..4d4de24
--- /dev/null
+++ b/res/drawable-nodpi/gentle_notifications_shade_lock.png
Binary files differ
diff --git a/res/drawable-nodpi/gentle_notifications_shade_status.png b/res/drawable-nodpi/gentle_notifications_shade_status.png
new file mode 100644
index 0000000..432dc3f
--- /dev/null
+++ b/res/drawable-nodpi/gentle_notifications_shade_status.png
Binary files differ
diff --git a/res/drawable-nodpi/gentle_notifications_shade_status_lock.png b/res/drawable-nodpi/gentle_notifications_shade_status_lock.png
new file mode 100644
index 0000000..e8238dc
--- /dev/null
+++ b/res/drawable-nodpi/gentle_notifications_shade_status_lock.png
Binary files differ
diff --git a/res/layout/drawable_layout.xml b/res/layout/drawable_layout.xml
new file mode 100644
index 0000000..fe5d4c4
--- /dev/null
+++ b/res/layout/drawable_layout.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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
+ -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+
+ <ImageView
+ android:id="@+id/drawable"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"/>
+</FrameLayout>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 93b7fa2..53e9248 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7872,6 +7872,33 @@
<!-- Configure notifications: value for swipe direction [CHAR LIMIT=100] -->
<string name="swipe_direction_rtl">Swipe left to dismiss, right to show menu</string>
+ <!-- Configure notifications: link to education/gentle notification settings [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_title">Gentle notifications</string>
+
+ <!-- Gentle notifications settings : header for selecting where gentle notifications should appear [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_also_display">Also display in</string>
+
+ <!-- Gentle notifications settings: display in status bar [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_status">Status bar</string>
+
+ <!-- Gentle notifications settings: display in lock screen [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_lock">Lock screen</string>
+
+ <!-- Gentle notifications footer: what are gentle notification [CHAR LIMIT=NONE] -->
+ <string name="gentle_notifications_education">Gentle notifications are always silent and always appear in the pull-down shade</string>
+
+ <!-- Gentle notifications settings: display only in shade [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_summary_shade">Display in pull-down shade only</string>
+
+ <!-- Gentle notifications settings: display in shade and on the lock screen [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_summary_shade_lock">Display in pull-down shade & on lock screen</string>
+
+ <!-- Gentle notifications settings: display in shade and on status bar [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_summary_shade_status">Display in pull-down shade & status bar</string>
+
+ <!-- Gentle notifications settings: display on all surfaces [CHAR LIMIT=100] -->
+ <string name="gentle_notifications_display_summary_shade_status_lock">Display in pull-down shade, status bar & on lock screen</string>
+
<!-- Configure Notifications: Title for the pulse notification light option. [CHAR LIMIT=30] -->
<string name="notification_pulse_title">Blink light</string>
diff --git a/res/xml/configure_notification_settings.xml b/res/xml/configure_notification_settings.xml
index dd2cf86..af27869 100644
--- a/res/xml/configure_notification_settings.xml
+++ b/res/xml/configure_notification_settings.xml
@@ -26,11 +26,11 @@
settings:controller="com.android.settings.widget.VideoPreferenceController"
android:persistent="false" />
- <SwitchPreference
- android:key="hide_silent_icons"
- android:title="@string/hide_silent_icons_title"
- android:summary="@string/hide_silent_icons_summary"
- settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
+ <Preference
+ android:key="gentle_notifications"
+ android:title="@string/gentle_notifications_title"
+ settings:controller="com.android.settings.notification.GentleNotificationsPreferenceController"
+ android:fragment="com.android.settings.notification.GentleNotificationSettings"/>
<PreferenceCategory
android:key="configure_notifications_smart"
diff --git a/res/xml/gentle_notification_settings.xml b/res/xml/gentle_notification_settings.xml
new file mode 100644
index 0000000..80061ba
--- /dev/null
+++ b/res/xml/gentle_notification_settings.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="@string/gentle_notifications_title"
+ android:key="gentle_notification_settings">
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="gentle_notifications_drawable"
+ android:title="@string/summary_placeholder"
+ android:layout="@layout/drawable_layout"
+ settings:controller="com.android.settings.notification.GentleDrawablePreferenceController"
+ android:order="1"
+ settings:allowDividerBelow="true"
+ android:persistent="false" />
+
+ <Preference
+ android:key="gentle_notifications_footer"
+ android:title="@string/gentle_notifications_education"
+ android:order="2"
+ android:icon="@drawable/ic_info_outline_24"
+ style="?attr/footerPreferenceStyle"
+ settings:allowDividerAbove="true"
+ android:clickable="false"
+ android:selectable="false" />
+
+ <PreferenceCategory
+ android:key="gentle_notifications_settings"
+ android:title="@string/gentle_notifications_also_display"
+ android:order="3">
+ <SwitchPreference
+ android:key="silent_icons"
+ android:title="@string/gentle_notifications_display_status"
+ settings:controller="com.android.settings.notification.SilentStatusBarPreferenceController" />
+
+ <SwitchPreference
+ android:key="lock_screen"
+ android:title="@string/gentle_notifications_display_lock"
+ settings:controller="com.android.settings.notification.SilentLockscreenPreferenceController" />
+ </PreferenceCategory>
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index a06bb77..600b9e8 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -25,7 +25,6 @@
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionPlan;
import android.text.TextUtils;
-import android.text.format.Formatter;
import android.util.Log;
import android.util.RecurrenceRule;
@@ -247,7 +246,7 @@
summaryPreference.setChartEnabled(false);
} else {
summaryPreference.setChartEnabled(true);
- summaryPreference.setLabels(Formatter.formatFileSize(mContext, 0 /* sizeBytes */),
+ summaryPreference.setLabels(DataUsageUtils.formatDataUsage(mContext, 0 /* sizeBytes */),
DataUsageUtils.formatDataUsage(mContext, mDataBarSize));
summaryPreference.setProgress(mDataplanUse / (float) mDataBarSize);
}
diff --git a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
index 8b6d10a..0551fc2 100644
--- a/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/WifiDataUsageSummaryPreferenceController.java
@@ -19,7 +19,6 @@
import android.app.Activity;
import android.net.NetworkTemplate;
import android.telephony.SubscriptionManager;
-import android.text.format.Formatter;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
@@ -28,7 +27,7 @@
import com.android.settingslib.net.DataUsageController;
/**
- * The controller displays a data usage chart for the specified Wi-Fi network.
+ * The controller displays a data usage chart for the specified Wi-Fi network.
*/
public class WifiDataUsageSummaryPreferenceController extends DataUsageSummaryPreferenceController {
final String mNetworkId;
@@ -66,7 +65,7 @@
// TODO(b/126142293): Passpoint Wi-Fi should have limit of data usage and time remaining
mPreference.setProgress(100);
- mPreference.setLabels(Formatter.formatFileSize(mContext, /* sizeBytes */ 0),
+ mPreference.setLabels(DataUsageUtils.formatDataUsage(mContext, /* sizeBytes */ 0),
DataUsageUtils.formatDataUsage(mContext, info.usageLevel));
}
}
diff --git a/src/com/android/settings/network/telephony/DataUsagePreferenceController.java b/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
index f9e0a97..3f55003 100644
--- a/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
+++ b/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
@@ -28,6 +28,7 @@
import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.datausage.DataUsageUtils;
import com.android.settingslib.net.DataUsageController;
/**
@@ -77,7 +78,7 @@
if (enabled) {
preference.setSummary(mContext.getString(R.string.data_usage_template,
- Formatter.formatFileSize(mContext, mDataUsageInfo.usageLevel),
+ DataUsageUtils.formatDataUsage(mContext, mDataUsageInfo.usageLevel),
mDataUsageInfo.period));
}
}
diff --git a/src/com/android/settings/notification/ConfigureNotificationSettings.java b/src/com/android/settings/notification/ConfigureNotificationSettings.java
index d9d2b9b..5f9cf5f 100644
--- a/src/com/android/settings/notification/ConfigureNotificationSettings.java
+++ b/src/com/android/settings/notification/ConfigureNotificationSettings.java
@@ -21,10 +21,13 @@
import android.app.Activity;
import android.app.Application;
import android.app.settings.SettingsEnums;
+import android.app.usage.IUsageStatsManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.ServiceManager;
import android.os.UserHandle;
+import android.os.UserManager;
import android.provider.SearchIndexableResource;
import android.text.TextUtils;
@@ -112,7 +115,9 @@
lifecycle.addObserver(lockScreenNotificationController);
}
controllers.add(new RecentNotifyingAppsPreferenceController(
- context, new NotificationBackend(), app, host));
+ context, new NotificationBackend(), IUsageStatsManager.Stub.asInterface(
+ ServiceManager.getService(Context.USAGE_STATS_SERVICE)),
+ context.getSystemService(UserManager.class), app, host));
controllers.add(lockScreenNotificationController);
controllers.add(new NotificationRingtonePreferenceController(context) {
@Override
diff --git a/src/com/android/settings/notification/GentleDrawablePreferenceController.java b/src/com/android/settings/notification/GentleDrawablePreferenceController.java
new file mode 100644
index 0000000..cdadf5a
--- /dev/null
+++ b/src/com/android/settings/notification/GentleDrawablePreferenceController.java
@@ -0,0 +1,81 @@
+/*
+ * 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 android.content.Context;
+import android.provider.Settings;
+import android.widget.ImageView;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.widget.LayoutPreference;
+
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
+
+public class GentleDrawablePreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting
+ static final int ON = 1;
+
+ private NotificationBackend mBackend;
+
+ public GentleDrawablePreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mBackend = new NotificationBackend();
+ }
+
+ @VisibleForTesting
+ void setBackend(NotificationBackend backend) {
+ mBackend = backend;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ LayoutPreference pref = (LayoutPreference) preference;
+ boolean showOnLockscreen = showOnLockscreen();
+ boolean showOnStatusBar = showOnStatusBar();
+
+ ImageView view = pref.findViewById(R.id.drawable);
+
+ if (showOnLockscreen) {
+ if (showOnStatusBar) {
+ view.setImageResource(R.drawable.gentle_notifications_shade_status_lock);
+ } else {
+ view.setImageResource(R.drawable.gentle_notifications_shade_lock);
+ }
+ } else if (showOnStatusBar) {
+ view.setImageResource(R.drawable.gentle_notifications_shade_status);
+ } else {
+ view.setImageResource(R.drawable.gentle_notifications_shade);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ private boolean showOnLockscreen() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) == ON;
+ }
+
+ private boolean showOnStatusBar() {
+ return !mBackend.shouldHideSilentStatusBarIcons(mContext);
+ }
+}
diff --git a/src/com/android/settings/notification/GentleNotificationSettings.java b/src/com/android/settings/notification/GentleNotificationSettings.java
new file mode 100644
index 0000000..5de6ab7
--- /dev/null
+++ b/src/com/android/settings/notification/GentleNotificationSettings.java
@@ -0,0 +1,74 @@
+/*
+ * 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 android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.Arrays;
+import java.util.List;
+
+@SearchIndexable
+public class GentleNotificationSettings extends DashboardFragment {
+ private static final String TAG = "GentleNotiSettings";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.GENTLE_NOTIFICATIONS_SCREEN;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.gentle_notification_settings;
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ use(SilentStatusBarPreferenceController.class).setListener(
+ shown -> updatePreferenceStates());
+
+ use(SilentLockscreenPreferenceController.class).setListener(
+ shown -> updatePreferenceStates());
+ }
+
+ /**
+ * For Search.
+ */
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(
+ Context context, boolean enabled) {
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.gentle_notification_settings;
+ return Arrays.asList(sir);
+ }
+ };
+}
diff --git a/src/com/android/settings/notification/GentleNotificationsPreferenceController.java b/src/com/android/settings/notification/GentleNotificationsPreferenceController.java
new file mode 100644
index 0000000..97e4e25
--- /dev/null
+++ b/src/com/android/settings/notification/GentleNotificationsPreferenceController.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+import androidx.annotation.VisibleForTesting;
+
+public class GentleNotificationsPreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting
+ static final int ON = 1;
+
+ private NotificationBackend mBackend;
+
+ public GentleNotificationsPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ mBackend = new NotificationBackend();
+ }
+
+ @VisibleForTesting
+ void setBackend(NotificationBackend backend) {
+ mBackend = backend;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ boolean showOnLockscreen = showOnLockscreen();
+ boolean showOnStatusBar = showOnStatusBar();
+
+ if (showOnLockscreen) {
+ if (showOnStatusBar) {
+ return mContext.getString(
+ R.string.gentle_notifications_display_summary_shade_status_lock);
+ } else {
+ return mContext.getString(R.string.gentle_notifications_display_summary_shade_lock);
+ }
+ } else if (showOnStatusBar) {
+ return mContext.getString(R.string.gentle_notifications_display_summary_shade_status);
+ } else {
+ return mContext.getString(R.string.gentle_notifications_display_summary_shade);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ private boolean showOnLockscreen() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) == ON;
+ }
+
+ private boolean showOnStatusBar() {
+ return !mBackend.shouldHideSilentStatusBarIcons(mContext);
+ }
+}
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 747c541..7d7ca82 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -312,15 +312,6 @@
}
}
- public List<NotifyingApp> getRecentApps() {
- try {
- return sINM.getRecentNotifyingAppsForUser(UserHandle.myUserId()).getList();
- } catch (Exception e) {
- Log.w(TAG, "Error calling NoMan", e);
- return new ArrayList<>();
- }
- }
-
public int getBlockedAppCount() {
try {
return sINM.getBlockedAppCount(UserHandle.myUserId());
diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
index 8122df7..1fe7e7d 100644
--- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
+++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java
@@ -18,11 +18,15 @@
import android.app.Application;
import android.app.settings.SettingsEnums;
+import android.app.usage.IUsageStatsManager;
+import android.app.usage.UsageEvents;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
+import android.os.RemoteException;
import android.os.UserHandle;
+import android.os.UserManager;
import android.service.notification.NotifyingApp;
import android.text.TextUtils;
import android.util.ArrayMap;
@@ -30,13 +34,8 @@
import android.util.IconDrawableFactory;
import android.util.Log;
-import androidx.annotation.VisibleForTesting;
-import androidx.fragment.app.Fragment;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
import com.android.settings.R;
+import com.android.settings.Utils;
import com.android.settings.applications.AppInfoBase;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
@@ -47,11 +46,18 @@
import com.android.settingslib.utils.StringUtil;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import androidx.annotation.VisibleForTesting;
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceScreen;
+
/**
* This controller displays a list of recently used apps and a "See all" button. If there is
* no recently used app, "See all" will be displayed as "Notifications".
@@ -66,28 +72,35 @@
@VisibleForTesting
static final String KEY_SEE_ALL = "all_notifications";
private static final int SHOW_RECENT_APP_COUNT = 5;
+ private static final int DAYS = 3;
private static final Set<String> SKIP_SYSTEM_PACKAGES = new ArraySet<>();
private final Fragment mHost;
private final PackageManager mPm;
private final NotificationBackend mNotificationBackend;
+ private IUsageStatsManager mUsageStatsManager;
private final int mUserId;
private final IconDrawableFactory mIconDrawableFactory;
- private List<NotifyingApp> mApps;
+ private Calendar mCal;
+ List<NotifyingApp> mApps;
private final ApplicationsState mApplicationsState;
private PreferenceCategory mCategory;
private Preference mSeeAllPref;
private Preference mDivider;
+ protected List<Integer> mUserIds;
public RecentNotifyingAppsPreferenceController(Context context, NotificationBackend backend,
+ IUsageStatsManager usageStatsManager, UserManager userManager,
Application app, Fragment host) {
- this(context, backend, app == null ? null : ApplicationsState.getInstance(app), host);
+ this(context, backend, usageStatsManager, userManager,
+ app == null ? null : ApplicationsState.getInstance(app), host);
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
RecentNotifyingAppsPreferenceController(Context context, NotificationBackend backend,
+ IUsageStatsManager usageStatsManager, UserManager userManager,
ApplicationsState appState, Fragment host) {
super(context);
mIconDrawableFactory = IconDrawableFactory.newInstance(context);
@@ -96,6 +109,13 @@
mHost = host;
mApplicationsState = appState;
mNotificationBackend = backend;
+ mUsageStatsManager = usageStatsManager;
+ mUserIds = new ArrayList<>();
+ mUserIds.add(mContext.getUserId());
+ int workUserId = Utils.getManagedProfileId(userManager, mContext.getUserId());
+ if (workUserId != UserHandle.USER_NULL) {
+ mUserIds.add(workUserId);
+ }
}
@Override
@@ -145,7 +165,48 @@
@VisibleForTesting
void reloadData() {
- mApps = mNotificationBackend.getRecentApps();
+ mApps = new ArrayList<>();
+ mCal = Calendar.getInstance();
+ mCal.add(Calendar.DAY_OF_YEAR, -DAYS);
+ for (int userId : mUserIds) {
+ UsageEvents events = null;
+ try {
+ events = mUsageStatsManager.queryEventsForUser(mCal.getTimeInMillis(),
+ System.currentTimeMillis(), userId, mContext.getPackageName());
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ if (events != null) {
+
+ ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
+
+ UsageEvents.Event event = new UsageEvents.Event();
+ while (events.hasNextEvent()) {
+ events.getNextEvent(event);
+
+ if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
+ NotifyingApp app =
+ aggregatedStats.get(getKey(userId, event.getPackageName()));
+ if (app == null) {
+ app = new NotifyingApp();
+ aggregatedStats.put(getKey(userId, event.getPackageName()), app);
+ app.setPackage(event.getPackageName());
+ app.setUserId(userId);
+ }
+ if (event.getTimeStamp() > app.getLastNotified()) {
+ app.setLastNotified(event.getTimeStamp());
+ }
+ }
+
+ }
+
+ mApps.addAll(aggregatedStats.values());
+ }
+ }
+ }
+
+ private static String getKey(int userId, String pkg) {
+ return userId + "|" + pkg;
}
private void displayOnlyAllAppsLink() {
@@ -185,7 +246,7 @@
// Bind recent apps to existing prefs if possible, or create a new pref.
final String pkgName = app.getPackage();
final ApplicationsState.AppEntry appEntry =
- mApplicationsState.getEntry(app.getPackage(), mUserId);
+ mApplicationsState.getEntry(app.getPackage(), app.getUserId());
if (appEntry == null) {
continue;
}
diff --git a/src/com/android/settings/notification/SilentLockscreenPreferenceController.java b/src/com/android/settings/notification/SilentLockscreenPreferenceController.java
new file mode 100644
index 0000000..219d312
--- /dev/null
+++ b/src/com/android/settings/notification/SilentLockscreenPreferenceController.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+import com.google.common.annotations.VisibleForTesting;
+
+public class SilentLockscreenPreferenceController extends TogglePreferenceController {
+
+ private static final String KEY = "lock_screen";
+ private Listener mListener;
+
+ public SilentLockscreenPreferenceController(Context context) {
+ super(context, KEY);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0) == 1;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, isChecked ? 1 : 0);
+ if (mListener != null) {
+ mListener.onChange(isChecked);
+ }
+ return true;
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Settings.Secure.getInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1) != 0
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ public void setListener(Listener listener) {
+ mListener = listener;
+ }
+
+ interface Listener {
+ void onChange(boolean shown);
+ }
+}
+
+
diff --git a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
index 5bf943a..e561508 100644
--- a/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
+++ b/src/com/android/settings/notification/SilentStatusBarPreferenceController.java
@@ -28,9 +28,10 @@
public class SilentStatusBarPreferenceController extends TogglePreferenceController {
- private static final String KEY = "hide_silent_icons";
+ private static final String KEY = "silent_icons";
private static final int MY_USER_ID = UserHandle.myUserId();
private NotificationBackend mBackend;
+ private Listener mListener;
public SilentStatusBarPreferenceController(Context context) {
super(context, KEY);
@@ -44,12 +45,15 @@
@Override
public boolean isChecked() {
- return mBackend.shouldHideSilentStatusBarIcons(mContext);
+ return !mBackend.shouldHideSilentStatusBarIcons(mContext);
}
@Override
public boolean setChecked(boolean isChecked) {
- mBackend.setHideSilentStatusIcons(isChecked);
+ mBackend.setHideSilentStatusIcons(!isChecked);
+ if (mListener != null) {
+ mListener.onChange(isChecked);
+ }
return true;
}
@@ -60,6 +64,14 @@
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
}
+ public void setListener(Listener listener) {
+ mListener = listener;
+ }
+
+ interface Listener {
+ void onChange(boolean shown);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
index 348f8b4..5ffda81 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
@@ -18,20 +18,15 @@
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import android.app.Activity;
-import android.app.usage.NetworkStats;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.content.Intent;
+import android.net.TrafficStats;
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -114,16 +109,24 @@
}
@Test
- public void updateState_noUsageData_shouldDisablePreference() throws Exception {
- final NetworkStatsManager networkStatsManager = mock(NetworkStatsManager.class);
- when(networkStatsManager.querySummaryForDevice(anyInt() /* networkType */,
- anyString() /* subscriberId */, anyLong() /* startTime */, anyLong() /* endTime */))
- .thenReturn(mock(NetworkStats.Bucket.class));
+ public void updateState_noUsageData_shouldDisablePreference() {
ReflectionHelpers.setField(
- mController, "mDataUsageInfo", new DataUsageController.DataUsageInfo());
+ mController, "mDataUsageInfo", new DataUsageController.DataUsageInfo());
mController.updateState(mPreference);
assertThat(mPreference.isEnabled()).isFalse();
}
+
+ @Test
+ public void updateState_shouldUseIECUnit() {
+ final DataUsageController.DataUsageInfo usageInfo = new DataUsageController.DataUsageInfo();
+ usageInfo.usageLevel = TrafficStats.MB_IN_BYTES;
+ ReflectionHelpers.setField(mController, "mDataUsageInfo", usageInfo);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary().toString())
+ .contains("1.00 MB");
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/GentleDrawablePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/GentleDrawablePreferenceControllerTest.java
new file mode 100644
index 0000000..c8d1e01
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/GentleDrawablePreferenceControllerTest.java
@@ -0,0 +1,113 @@
+/*
+ * 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 com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.widget.ImageView;
+
+import com.android.settings.R;
+import com.android.settingslib.widget.LayoutPreference;
+
+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;
+
+import androidx.preference.Preference;
+
+@RunWith(RobolectricTestRunner.class)
+public class GentleDrawablePreferenceControllerTest {
+
+ private Context mContext;
+
+ private GentleDrawablePreferenceController mController;
+ @Mock
+ private LayoutPreference mPreference;
+ @Mock
+ NotificationBackend mBackend;
+ @Mock
+ ImageView mView;
+
+ private static final String KEY = "gentle_notifications";
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new GentleDrawablePreferenceController(mContext, KEY);
+ mController.setBackend(mBackend);
+ when(mPreference.findViewById(R.id.drawable)).thenReturn(mView);
+ }
+
+ @Test
+ public void display_shouldDisplay() {
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void updateState_lock() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
+
+ mController.updateState(mPreference);
+
+ verify(mView).setImageResource(R.drawable.gentle_notifications_shade_lock);
+ }
+
+ @Test
+ public void updateState_status() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
+
+ mController.updateState(mPreference);
+
+ verify(mView).setImageResource(R.drawable.gentle_notifications_shade_status);
+ }
+
+ @Test
+ public void updateState_both() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
+
+ mController.updateState(mPreference);
+
+ verify(mView).setImageResource(R.drawable.gentle_notifications_shade_status_lock);
+ }
+
+ @Test
+ public void updateState_neither() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
+
+ mController.updateState(mPreference);
+
+ verify(mView).setImageResource(R.drawable.gentle_notifications_shade);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/GentleNotificationsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/GentleNotificationsPreferenceControllerTest.java
new file mode 100644
index 0000000..4821322
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/GentleNotificationsPreferenceControllerTest.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.NOTIFICATION_BUBBLES;
+
+import static com.android.settings.notification.BadgingNotificationPreferenceController.OFF;
+import static com.android.settings.notification.BadgingNotificationPreferenceController.ON;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
+
+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;
+
+import androidx.preference.Preference;
+
+@RunWith(RobolectricTestRunner.class)
+public class GentleNotificationsPreferenceControllerTest {
+
+ private Context mContext;
+
+ @Mock
+ NotificationBackend mBackend;
+
+ private GentleNotificationsPreferenceController mController;
+ private Preference mPreference;
+
+ private static final String KEY = "gentle_notifications";
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new GentleNotificationsPreferenceController(mContext, KEY);
+ mController.setBackend(mBackend);
+ mPreference = new Preference(mContext);
+ }
+
+ @Test
+ public void display_shouldDisplay() {
+ assertThat(mPreference.isVisible()).isTrue();
+ }
+
+ @Test
+ public void getSummary_lock() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
+
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getString(R.string.gentle_notifications_display_summary_shade_lock));
+ }
+
+ @Test
+ public void getSummary_status() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
+
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getString(R.string.gentle_notifications_display_summary_shade_status));
+ }
+
+ @Test
+ public void getSummary_both() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(false);
+
+ assertThat(mController.getSummary()).isEqualTo(mContext.getString(
+ R.string.gentle_notifications_display_summary_shade_status_lock));
+ }
+
+ @Test
+ public void getSummary_neither() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
+ when(mBackend.shouldHideSilentStatusBarIcons(mContext)).thenReturn(true);
+
+ assertThat(mController.getSummary()).isEqualTo(
+ mContext.getString(R.string.gentle_notifications_display_summary_shade));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java
index 4221a21..d47d125 100644
--- a/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/RecentNotifyingAppsPreferenceControllerTest.java
@@ -20,8 +20,10 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -31,22 +33,20 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.usage.IUsageStatsManager;
+import android.app.usage.UsageEvents;
+import android.app.usage.UsageEvents.Event;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
+import android.os.Parcel;
import android.os.UserHandle;
import android.os.UserManager;
import android.service.notification.NotifyingApp;
import android.text.TextUtils;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentActivity;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceCategory;
-import androidx.preference.PreferenceScreen;
-
import com.android.settings.R;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
@@ -67,6 +67,12 @@
import java.util.ArrayList;
import java.util.List;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceCategory;
+import androidx.preference.PreferenceScreen;
+
@RunWith(RobolectricTestRunner.class)
public class RecentNotifyingAppsPreferenceControllerTest {
@@ -94,6 +100,8 @@
private Fragment mHost;
@Mock
private FragmentActivity mActivity;
+ @Mock
+ private IUsageStatsManager mIUsageStatsManager;
private Context mContext;
private RecentNotifyingAppsPreferenceController mController;
@@ -104,9 +112,10 @@
mContext = spy(RuntimeEnvironment.application);
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
doReturn(mPackageManager).when(mContext).getPackageManager();
+ when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] {0});
mController = new RecentNotifyingAppsPreferenceController(
- mContext, mBackend, mAppState, mHost);
+ mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
when(mScreen.findPreference(anyString())).thenReturn(mCategory);
when(mScreen.findPreference(RecentNotifyingAppsPreferenceController.KEY_SEE_ALL))
@@ -135,7 +144,7 @@
@Test
public void onDisplayAndUpdateState_shouldRefreshUi() {
mController = spy(new RecentNotifyingAppsPreferenceController(
- mContext, null, (ApplicationsState) null, null));
+ mContext, null, mIUsageStatsManager, mUserManager, (ApplicationsState) null, null));
doNothing().when(mController).refreshUi(mContext);
@@ -158,32 +167,41 @@
}
@Test
- public void display_showRecents() {
- final List<NotifyingApp> apps = new ArrayList<>();
- final NotifyingApp app1 = new NotifyingApp()
- .setPackage("pkg.class")
- .setLastNotified(System.currentTimeMillis());
- final NotifyingApp app2 = new NotifyingApp()
- .setLastNotified(System.currentTimeMillis())
- .setPackage("com.android.settings");
- final NotifyingApp app3 = new NotifyingApp()
- .setLastNotified(System.currentTimeMillis() - 1000)
- .setPackage("pkg.class2");
+ public void display_showRecents() throws Exception {
- apps.add(app1);
- apps.add(app2);
- apps.add(app3);
+ List<Event> events = new ArrayList<>();
+ Event app = new Event();
+ app.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app.mPackage = "a";
+ app.mTimeStamp = System.currentTimeMillis();
+ events.add(app);
+ Event app1 = new Event();
+ app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app1.mPackage = "com.android.settings";
+ app1.mTimeStamp = System.currentTimeMillis();
+ events.add(app1);
+ Event app2 = new Event();
+ app2.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app2.mPackage = "pkg.class2";
+ app2.mTimeStamp = System.currentTimeMillis() - 1000;
+ events.add(app2);
// app1, app2 are valid apps. app3 is invalid.
- when(mAppState.getEntry(app1.getPackage(), UserHandle.myUserId()))
+ when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
.thenReturn(mAppEntry);
- when(mAppState.getEntry(app2.getPackage(), UserHandle.myUserId()))
+ when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId()))
.thenReturn(mAppEntry);
- when(mAppState.getEntry(app3.getPackage(), UserHandle.myUserId()))
+ when(mAppState.getEntry(app2.getPackageName(), UserHandle.myUserId()))
.thenReturn(null);
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
new ResolveInfo());
- when(mBackend.getRecentApps()).thenReturn(apps);
+
+ UsageEvents usageEvents = getUsageEvents(
+ new String[] {app.getPackageName(), app1.getPackageName(), app2.getPackageName()},
+ events);
+ when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
+
mAppEntry.info = mApplicationInfo;
mController.displayPreference(mScreen);
@@ -198,34 +216,37 @@
}
@Test
- public void display_showRecentsWithInstantApp() {
- // Regular app.
- final List<NotifyingApp> apps = new ArrayList<>();
- final NotifyingApp app1 = new NotifyingApp().
- setLastNotified(System.currentTimeMillis())
- .setPackage("com.foo.bar");
- apps.add(app1);
-
- // Instant app.
- final NotifyingApp app2 = new NotifyingApp()
- .setLastNotified(System.currentTimeMillis() + 200)
- .setPackage("com.foo.barinstant");
- apps.add(app2);
+ public void display_showRecentsWithInstantApp() throws Exception {
+ List<Event> events = new ArrayList<>();
+ Event app = new Event();
+ app.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app.mPackage = "com.foo.bar";
+ app.mTimeStamp = System.currentTimeMillis();
+ events.add(app);
+ Event app1 = new Event();
+ app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app1.mPackage = "com.foo.barinstant";
+ app1.mTimeStamp = System.currentTimeMillis() + 200;
+ events.add(app1);
+ UsageEvents usageEvents = getUsageEvents(
+ new String[] {"com.foo.bar", "com.foo.barinstant"}, events);
+ when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
app1Entry.info = mApplicationInfo;
app2Entry.info = mApplicationInfo;
- when(mAppState.getEntry(app1.getPackage(), UserHandle.myUserId())).thenReturn(app1Entry);
- when(mAppState.getEntry(app2.getPackage(), UserHandle.myUserId())).thenReturn(app2Entry);
+ when(mAppState.getEntry(
+ app.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
+ when(mAppState.getEntry(
+ app1.getPackageName(), UserHandle.myUserId())).thenReturn(app2Entry);
// Only the regular app app1 should have its intent resolve.
- when(mPackageManager.resolveActivity(argThat(intentMatcher(app1.getPackage())),
+ when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())),
anyInt())).thenReturn(new ResolveInfo());
- when(mBackend.getRecentApps()).thenReturn(apps);
-
// Make sure app2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (ApplicationInfo info) -> {
@@ -241,23 +262,27 @@
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
verify(mCategory, times(2)).addPreference(prefCaptor.capture());
List<Preference> prefs = prefCaptor.getAllValues();
- assertThat(prefs.get(1).getKey()).isEqualTo(app1.getPackage());
- assertThat(prefs.get(0).getKey()).isEqualTo(app2.getPackage());
+ assertThat(prefs.get(1).getKey()).isEqualTo(app.getPackageName());
+ assertThat(prefs.get(0).getKey()).isEqualTo(app1.getPackageName());
}
@Test
- public void display_showRecents_formatSummary() {
- final List<NotifyingApp> apps = new ArrayList<>();
- final NotifyingApp app1 = new NotifyingApp()
- .setLastNotified(System.currentTimeMillis())
- .setPackage("pkg.class");
- apps.add(app1);
+ public void display_showRecents_formatSummary() throws Exception {
+ List<Event> events = new ArrayList<>();
+ Event app = new Event();
+ app.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app.mPackage = "pkg.class";
+ app.mTimeStamp = System.currentTimeMillis();
+ events.add(app);
+ UsageEvents usageEvents = getUsageEvents(new String[] {"pkg.class"}, events);
+ when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
- when(mAppState.getEntry(app1.getPackage(), UserHandle.myUserId()))
+ when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
.thenReturn(mAppEntry);
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
new ResolveInfo());
- when(mBackend.getRecentApps()).thenReturn(apps);
+
mAppEntry.info = mApplicationInfo;
mController.displayPreference(mScreen);
@@ -265,6 +290,66 @@
verify(mCategory).addPreference(argThat(summaryMatches("Just now")));
}
+ @Test
+ public void reloadData() throws Exception {
+ when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] {0, 10});
+
+ mController = new RecentNotifyingAppsPreferenceController(
+ mContext, mBackend, mIUsageStatsManager, mUserManager, mAppState, mHost);
+
+ List<Event> events = new ArrayList<>();
+ Event app = new Event();
+ app.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app.mPackage = "b";
+ app.mTimeStamp = 1;
+ events.add(app);
+ Event app1 = new Event();
+ app1.mEventType = Event.MAX_EVENT_TYPE;
+ app1.mPackage = "com.foo.bar";
+ app1.mTimeStamp = 10;
+ events.add(app1);
+ UsageEvents usageEvents = getUsageEvents(
+ new String[] {"b", "com.foo.bar"}, events);
+ when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(0), anyString()))
+ .thenReturn(usageEvents);
+
+ List<Event> events10 = new ArrayList<>();
+ Event app10 = new Event();
+ app10.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app10.mPackage = "a";
+ app10.mTimeStamp = 2;
+ events10.add(app10);
+ Event app10a = new Event();
+ app10a.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ app10a.mPackage = "a";
+ app10a.mTimeStamp = 20;
+ events10.add(app10a);
+ UsageEvents usageEvents10 = getUsageEvents(
+ new String[] {"a"}, events10);
+ when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), eq(10), anyString()))
+ .thenReturn(usageEvents10);
+
+ mController.reloadData();
+
+ assertThat(mController.mApps.size()).isEqualTo(2);
+ boolean foundPkg0 = false;
+ boolean foundPkg10 = false;
+ for (NotifyingApp notifyingApp : mController.mApps) {
+ if (notifyingApp.getLastNotified() == 20
+ && notifyingApp.getPackage().equals("a")
+ && notifyingApp.getUserId() == 10) {
+ foundPkg10 = true;
+ }
+ if (notifyingApp.getLastNotified() == 1
+ && notifyingApp.getPackage().equals("b")
+ && notifyingApp.getUserId() == 0) {
+ foundPkg0 = true;
+ }
+ }
+ assertThat(foundPkg0).isTrue();
+ assertThat(foundPkg10).isTrue();
+ }
+
private static ArgumentMatcher<Preference> summaryMatches(String expected) {
return preference -> TextUtils.equals(expected, preference.getSummary());
}
@@ -273,4 +358,13 @@
private static ArgumentMatcher<Intent> intentMatcher(String packageName) {
return intent -> packageName.equals(intent.getPackage());
}
+
+ private UsageEvents getUsageEvents(String[] pkgs, List<Event> events) {
+ UsageEvents usageEvents = new UsageEvents(events, pkgs);
+ Parcel parcel = Parcel.obtain();
+ parcel.setDataPosition(0);
+ usageEvents.writeToParcel(parcel, 0);
+ parcel.setDataPosition(0);
+ return UsageEvents.CREATOR.createFromParcel(parcel);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/SilentLockscreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentLockscreenPreferenceControllerTest.java
new file mode 100644
index 0000000..dcfdea5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/SilentLockscreenPreferenceControllerTest.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.notification;
+
+import static android.provider.Settings.Secure.NOTIFICATION_NEW_INTERRUPTION_MODEL;
+
+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.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+@RunWith(RobolectricTestRunner.class)
+public class SilentLockscreenPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private Context mContext;
+ private SilentLockscreenPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new SilentLockscreenPreferenceController(mContext);
+ mPreference = new Preference(mContext);
+ mPreference.setKey(mController.getPreferenceKey());
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ }
+
+ @Test
+ public void isAvailable_featureEnabled() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 1);
+ assertThat(mController.isAvailable()).isTrue();
+ }
+
+ @Test
+ public void isAvailable_featureDisabled() {
+ Settings.Secure.putInt(
+ mContext.getContentResolver(), NOTIFICATION_NEW_INTERRUPTION_MODEL, 0);
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isChecked_settingIsOff_false() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0);
+ assertThat(mController.isChecked()).isFalse();
+ }
+
+ @Test
+ public void isChecked_settingIsOn_true() {
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1);
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void onPreferenceChange_on() {
+ mController.onPreferenceChange(mPreference, true);
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 0)).isEqualTo(1);
+ }
+
+ @Test
+ public void onPreferenceChange_off() {
+ mController.onPreferenceChange(mPreference, false);
+ assertThat(Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS, 1)).isEqualTo(0);
+ }
+
+ @Test
+ public void listenerTriggered() {
+ SilentLockscreenPreferenceController.Listener listener = mock(
+ SilentLockscreenPreferenceController.Listener.class);
+ mController.setListener(listener);
+
+ mController.setChecked(false);
+ verify(listener).onChange(false);
+
+ mController.setChecked(true);
+ verify(listener).onChange(true);
+ }
+}
+
diff --git a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
index 9dd8ff9..55a8549 100644
--- a/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/SilentStatusBarPreferenceControllerTest.java
@@ -21,6 +21,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.verify;
import static org.mockito.Mockito.when;
@@ -79,26 +80,39 @@
@Test
public void isChecked_settingIsOff_false() {
- when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
+ when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
assertThat(mController.isChecked()).isFalse();
}
@Test
public void isChecked_settingIsOn_true() {
- when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(true);
+ when(mBackend.shouldHideSilentStatusBarIcons(any())).thenReturn(false);
assertThat(mController.isChecked()).isTrue();
}
@Test
public void onPreferenceChange_on() {
mController.onPreferenceChange(mPreference, true);
- verify(mBackend).setHideSilentStatusIcons(true);
+ verify(mBackend).setHideSilentStatusIcons(false);
}
@Test
public void onPreferenceChange_off() {
mController.onPreferenceChange(mPreference, false);
- verify(mBackend).setHideSilentStatusIcons(false);
+ verify(mBackend).setHideSilentStatusIcons(true);
+ }
+
+ @Test
+ public void listenerTriggered() {
+ SilentStatusBarPreferenceController.Listener listener = mock(
+ SilentStatusBarPreferenceController.Listener.class);
+ mController.setListener(listener);
+
+ mController.setChecked(false);
+ verify(listener).onChange(false);
+
+ mController.setChecked(true);
+ verify(listener).onChange(true);
}
}