Merge "Remove DataSummaryUsageLegacy."
diff --git a/res/layout/preference_dropdown_material_settings.xml b/res/layout/preference_dropdown_material_settings.xml
deleted file mode 100644
index a3f5ab9..0000000
--- a/res/layout/preference_dropdown_material_settings.xml
+++ /dev/null
@@ -1,35 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 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.
- -->
-
-
-<!-- Based off frameworks/base/core/res/res/layout/preference_dropdown_material.xml
- except that icon space in this layout is always reserved -->
-<FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <Spinner
- android:id="@+id/spinner"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_marginStart="@dimen/preference_no_icon_padding_start"
- android:visibility="invisible" />
-
- <include layout="@layout/preference_material"/>
-
-</FrameLayout>
\ No newline at end of file
diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml
index 6b632ca..a55f5ca 100644
--- a/res/values/styles_preference.xml
+++ b/res/values/styles_preference.xml
@@ -20,27 +20,27 @@
<resources>
<!-- Fragment style -->
- <style name="SettingsPreferenceFragmentStyle" parent="@style/PreferenceFragmentStyle.SettingsBase">
+ <style name="SettingsPreferenceFragmentStyle" parent="@style/PreferenceFragment.Material">
<item name="android:layout">@layout/preference_list_fragment</item>
</style>
- <style name="ApnPreference" parent="Preference.SettingsBase">
+ <style name="ApnPreference" parent="@style/Preference.Material">
<item name="android:layout">@layout/apn_preference_layout</item>
</style>
- <style name="SettingsSeekBarPreference" parent="Preference.SettingsBase">
+ <style name="SettingsSeekBarPreference" parent="@style/Preference.Material">
<item name="android:layout">@layout/preference_widget_seekbar_settings</item>
</style>
- <style name="SyncSwitchPreference" parent="Preference.SettingsBase">
+ <style name="SyncSwitchPreference" parent="@style/Preference.Material">
<item name="android:widgetLayout">@layout/preference_widget_sync_toggle</item>
</style>
- <style name="TwoStateButtonPreference" parent="Preference.SettingsBase">
+ <style name="TwoStateButtonPreference" parent="@style/Preference.Material">
<item name="android:layout">@layout/two_state_button</item>
</style>
- <style name="SettingsMultiSelectListPreference" parent="Preference.SettingsBase">
+ <style name="SettingsMultiSelectListPreference" parent="@style/Preference.Material">
<item name="android:positiveButtonText">@android:string/ok</item>
<item name="android:negativeButtonText">@android:string/cancel</item>
</style>
diff --git a/src/com/android/settings/applications/AppStateNotificationBridge.java b/src/com/android/settings/applications/AppStateNotificationBridge.java
index a96a3b1..6cf64c3 100644
--- a/src/com/android/settings/applications/AppStateNotificationBridge.java
+++ b/src/com/android/settings/applications/AppStateNotificationBridge.java
@@ -15,9 +15,13 @@
*/
package com.android.settings.applications;
+import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageEvents;
import android.app.usage.UsageStatsManager;
import android.content.Context;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.UserManager;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.view.View;
@@ -25,6 +29,7 @@
import android.widget.Switch;
import com.android.settings.R;
+import com.android.settings.Utils;
import com.android.settings.notification.NotificationBackend;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
@@ -33,6 +38,7 @@
import java.util.ArrayList;
import java.util.Comparator;
+import java.util.List;
import java.util.Map;
/**
@@ -42,17 +48,24 @@
public class AppStateNotificationBridge extends AppStateBaseBridge {
private final Context mContext;
- private UsageStatsManager mUsageStatsManager;
+ private IUsageStatsManager mUsageStatsManager;
+ protected List<Integer> mUserIds;
private NotificationBackend mBackend;
private static final int DAYS_TO_CHECK = 7;
public AppStateNotificationBridge(Context context, ApplicationsState appState,
- Callback callback, UsageStatsManager usageStatsManager,
- NotificationBackend backend) {
+ Callback callback, IUsageStatsManager usageStatsManager,
+ UserManager userManager, NotificationBackend backend) {
super(appState, callback);
mContext = context;
mUsageStatsManager = usageStatsManager;
mBackend = backend;
+ mUserIds = new ArrayList<>();
+ mUserIds.add(mContext.getUserId());
+ int workUserId = Utils.getManagedProfileId(userManager, mContext.getUserId());
+ if (workUserId != UserHandle.USER_NULL) {
+ mUserIds.add(workUserId);
+ }
}
@Override
@@ -62,7 +75,8 @@
final Map<String, NotificationsSentState> map = getAggregatedUsageEvents();
for (AppEntry entry : apps) {
- NotificationsSentState stats = map.get(entry.info.packageName);
+ NotificationsSentState stats =
+ map.get(getKey(UserHandle.getUserId(entry.info.uid), entry.info.packageName));
calculateAvgSentCounts(stats);
addBlockStatus(entry, stats);
entry.extraInfo = stats;
@@ -71,8 +85,8 @@
@Override
protected void updateExtraInfo(AppEntry entry, String pkg, int uid) {
- Map<String, NotificationsSentState> map = getAggregatedUsageEvents();
- NotificationsSentState stats = map.get(entry.info.packageName);
+ NotificationsSentState stats = getAggregatedUsageEvents(
+ UserHandle.getUserId(entry.info.uid), entry.info.packageName);
calculateAvgSentCounts(stats);
addBlockStatus(entry, stats);
entry.extraInfo = stats;
@@ -116,18 +130,59 @@
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
- UsageEvents events = mUsageStatsManager.queryEvents(startTime, now);
+ for (int userId : mUserIds) {
+ UsageEvents events = null;
+ try {
+ events = mUsageStatsManager.queryEventsForUser(
+ startTime, now, userId, mContext.getPackageName());
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ if (events != null) {
+ UsageEvents.Event event = new UsageEvents.Event();
+ while (events.hasNextEvent()) {
+ events.getNextEvent(event);
+ NotificationsSentState stats =
+ aggregatedStats.get(getKey(userId, event.getPackageName()));
+ if (stats == null) {
+ stats = new NotificationsSentState();
+ aggregatedStats.put(getKey(userId, event.getPackageName()), stats);
+ }
+
+ if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
+ if (event.getTimeStamp() > stats.lastSent) {
+ stats.lastSent = event.getTimeStamp();
+ }
+ stats.sentCount++;
+ }
+
+ }
+ }
+ }
+ return aggregatedStats;
+ }
+
+ protected NotificationsSentState getAggregatedUsageEvents(int userId, String pkg) {
+ NotificationsSentState stats = null;
+
+ long now = System.currentTimeMillis();
+ long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
+ UsageEvents events = null;
+ try {
+ events = mUsageStatsManager.queryEventsForPackageForUser(
+ startTime, now, userId, pkg, mContext.getPackageName());
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
if (events != null) {
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
events.getNextEvent(event);
- NotificationsSentState stats = aggregatedStats.get(event.getPackageName());
- if (stats == null) {
- stats = new NotificationsSentState();
- aggregatedStats.put(event.getPackageName(), stats);
- }
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
+ if (stats == null) {
+ stats = new NotificationsSentState();
+ }
if (event.getTimeStamp() > stats.lastSent) {
stats.lastSent = event.getTimeStamp();
}
@@ -136,7 +191,7 @@
}
}
- return aggregatedStats;
+ return stats;
}
private static NotificationsSentState getNotificationsSentState(AppEntry entry) {
@@ -149,6 +204,10 @@
return null;
}
+ protected static String getKey(int userId, String pkg) {
+ return userId + "|" + pkg;
+ }
+
public View.OnClickListener getSwitchOnClickListener(final AppEntry entry) {
if (entry != null) {
return v -> {
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 2250f28..dc9214e 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -41,6 +41,7 @@
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.app.Activity;
+import android.app.usage.IUsageStatsManager;
import android.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.Intent;
@@ -48,6 +49,7 @@
import android.content.pm.PackageItemInfo;
import android.os.Bundle;
import android.os.Environment;
+import android.os.ServiceManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.preference.PreferenceFrameLayout;
@@ -224,7 +226,8 @@
private View mSpinnerHeader;
private Spinner mFilterSpinner;
private FilterSpinnerAdapter mFilterAdapter;
- private UsageStatsManager mUsageStatsManager;
+ private IUsageStatsManager mUsageStatsManager;
+ private UserManager mUserManager;
private NotificationBackend mNotificationBackend;
private ResetAppsHelper mResetAppsHelper;
private String mVolumeUuid;
@@ -294,8 +297,9 @@
screenTitle = R.string.change_wifi_state_title;
} else if (className.equals(Settings.NotificationAppListActivity.class.getName())) {
mListType = LIST_TYPE_NOTIFICATION;
- mUsageStatsManager =
- (UsageStatsManager) getContext().getSystemService(Context.USAGE_STATS_SERVICE);
+ mUsageStatsManager = IUsageStatsManager.Stub.asInterface(
+ ServiceManager.getService(Context.USAGE_STATS_SERVICE));
+ mUserManager = UserManager.get(getContext());
mNotificationBackend = new NotificationBackend();
mSortOrder = R.id.sort_order_recent_notification;
screenTitle = R.string.app_notifications_title;
@@ -889,6 +893,7 @@
if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this,
manageApplications.mUsageStatsManager,
+ manageApplications.mUserManager,
manageApplications.mNotificationBackend);
} else if (mManageApplications.mListType == LIST_TYPE_USAGE_ACCESS) {
mExtraInfoBridge = new AppStateUsageBridge(mContext, mState, this);
diff --git a/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java b/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java
index 8814765..afb3431 100644
--- a/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingParentPreferenceController.java
@@ -16,12 +16,20 @@
package com.android.settings.gestures;
-import android.content.Context;
+import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE;
+import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
+import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
public class PreventRingingParentPreferenceController extends BasePreferenceController {
+ final String SECURE_KEY = VOLUME_HUSH_GESTURE;
+
public PreventRingingParentPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@@ -33,4 +41,21 @@
? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
}
+ @Override
+ public CharSequence getSummary() {
+ int value = Settings.Secure.getInt(
+ mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
+ int summary;
+ switch (value) {
+ case VOLUME_HUSH_VIBRATE:
+ summary = R.string.prevent_ringing_option_vibrate_summary;
+ break;
+ case VOLUME_HUSH_MUTE:
+ summary = R.string.prevent_ringing_option_mute_summary;
+ break;
+ default:
+ summary = R.string.prevent_ringing_option_none_summary;
+ }
+ return mContext.getText(summary);
+ }
}
diff --git a/src/com/android/settings/gestures/PreventRingingPreferenceController.java b/src/com/android/settings/gestures/PreventRingingPreferenceController.java
index be55151..7f685e5 100644
--- a/src/com/android/settings/gestures/PreventRingingPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingPreferenceController.java
@@ -50,8 +50,6 @@
@VisibleForTesting
boolean mVideoPaused;
- private final String SECURE_KEY = VOLUME_HUSH_GESTURE;
-
public PreventRingingPreferenceController(Context context, String key) {
super(context, key);
}
@@ -96,24 +94,6 @@
}
@Override
- public CharSequence getSummary() {
- int value = Settings.Secure.getInt(
- mContext.getContentResolver(), SECURE_KEY, VOLUME_HUSH_VIBRATE);
- int summary;
- switch (value) {
- case VOLUME_HUSH_VIBRATE:
- summary = R.string.prevent_ringing_option_vibrate_summary;
- break;
- case VOLUME_HUSH_MUTE:
- summary = R.string.prevent_ringing_option_mute_summary;
- break;
- default:
- summary = R.string.prevent_ringing_option_none_summary;
- }
- return mContext.getString(summary);
- }
-
- @Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
diff --git a/tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java b/tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java
index 9437a00..8e3bb42 100644
--- a/tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java
+++ b/tests/robotests/src/com/android/settings/applications/AppStateNotificationBridgeTest.java
@@ -36,17 +36,21 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
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.app.usage.UsageStatsManager;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.Looper;
import android.os.Parcel;
+import android.os.RemoteException;
+import android.os.UserHandle;
+import android.os.UserManager;
import android.view.ViewGroup;
import android.widget.Switch;
@@ -79,7 +83,9 @@
@Mock
private ApplicationsState mState;
@Mock
- private UsageStatsManager mUsageStats;
+ private IUsageStatsManager mUsageStats;
+ @Mock
+ private UserManager mUserManager;
@Mock
private NotificationBackend mBackend;
private Context mContext;
@@ -92,10 +98,12 @@
when(mState.getBackgroundLooper()).thenReturn(mock(Looper.class));
when(mBackend.getNotificationsBanned(anyString(), anyInt())).thenReturn(true);
when(mBackend.isSystemApp(any(), any())).thenReturn(true);
+ // most tests assume no work profile
+ when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
mContext = RuntimeEnvironment.application.getApplicationContext();
mBridge = new AppStateNotificationBridge(mContext, mState,
- mock(AppStateBaseBridge.Callback.class), mUsageStats, mBackend);
+ mock(AppStateBaseBridge.Callback.class), mUsageStats, mUserManager, mBackend);
}
private AppEntry getMockAppEntry(String pkg) {
@@ -115,14 +123,15 @@
}
@Test
- public void testGetAggregatedUsageEvents_noEvents() {
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(mock(UsageEvents.class));
+ public void testGetAggregatedUsageEvents_noEvents() throws Exception {
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(mock(UsageEvents.class));
assertThat(mBridge.getAggregatedUsageEvents()).isEmpty();
}
@Test
- public void testGetAggregatedUsageEvents_onlyNotificationEvents() {
+ public void testGetAggregatedUsageEvents_onlyNotificationEvents() throws Exception {
List<Event> events = new ArrayList<>();
Event good = new Event();
good.mEventType = Event.NOTIFICATION_INTERRUPTION;
@@ -136,14 +145,15 @@
events.add(bad);
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
Map<String, NotificationsSentState> map = mBridge.getAggregatedUsageEvents();
- assertThat(map.get(PKG1).sentCount).isEqualTo(1);
+ assertThat(map.get(mBridge.getKey(0, PKG1)).sentCount).isEqualTo(1);
}
@Test
- public void testGetAggregatedUsageEvents_multipleEventsAgg() {
+ public void testGetAggregatedUsageEvents_multipleEventsAgg() throws Exception {
List<Event> events = new ArrayList<>();
Event good = new Event();
good.mEventType = Event.NOTIFICATION_INTERRUPTION;
@@ -157,15 +167,16 @@
events.add(good1);
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
Map<String, NotificationsSentState> map = mBridge.getAggregatedUsageEvents();
- assertThat(map.get(PKG1).sentCount).isEqualTo(2);
- assertThat(map.get(PKG1).lastSent).isEqualTo(6);
+ assertThat(map.get(mBridge.getKey(0, PKG1)).sentCount).isEqualTo(2);
+ assertThat(map.get(mBridge.getKey(0, PKG1)).lastSent).isEqualTo(6);
}
@Test
- public void testGetAggregatedUsageEvents_multiplePkgs() {
+ public void testGetAggregatedUsageEvents_multiplePkgs() throws Exception {
List<Event> events = new ArrayList<>();
Event good = new Event();
good.mEventType = Event.NOTIFICATION_INTERRUPTION;
@@ -179,19 +190,21 @@
events.add(good1);
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
Map<String, NotificationsSentState> map
= mBridge.getAggregatedUsageEvents();
- assertThat(map.get(PKG1).sentCount).isEqualTo(1);
- assertThat(map.get(PKG2).sentCount).isEqualTo(1);
- assertThat(map.get(PKG1).lastSent).isEqualTo(6);
- assertThat(map.get(PKG2).lastSent).isEqualTo(1);
+ assertThat(map.get(mBridge.getKey(0, PKG1)).sentCount).isEqualTo(1);
+ assertThat(map.get(mBridge.getKey(0, PKG2)).sentCount).isEqualTo(1);
+ assertThat(map.get(mBridge.getKey(0, PKG1)).lastSent).isEqualTo(6);
+ assertThat(map.get(mBridge.getKey(0, PKG2)).lastSent).isEqualTo(1);
}
@Test
- public void testLoadAllExtraInfo_noEvents() {
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(mock(UsageEvents.class));
+ public void testLoadAllExtraInfo_noEvents() throws RemoteException {
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(mock(UsageEvents.class));
ArrayList<AppEntry> apps = new ArrayList<>();
apps.add(getMockAppEntry(PKG1));
when(mSession.getAllApps()).thenReturn(apps);
@@ -201,7 +214,7 @@
}
@Test
- public void testLoadAllExtraInfo_multipleEventsAgg() {
+ public void testLoadAllExtraInfo_multipleEventsAgg() throws RemoteException {
List<Event> events = new ArrayList<>();
for (int i = 0; i < 7; i++) {
Event good = new Event();
@@ -212,7 +225,8 @@
}
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
ArrayList<AppEntry> apps = new ArrayList<>();
apps.add(getMockAppEntry(PKG1));
@@ -229,7 +243,7 @@
}
@Test
- public void testLoadAllExtraInfo_multiplePkgs() {
+ public void testLoadAllExtraInfo_multiplePkgs() throws RemoteException {
List<Event> events = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Event good = new Event();
@@ -245,7 +259,8 @@
events.add(good1);
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
+ .thenReturn(usageEvents);
ArrayList<AppEntry> apps = new ArrayList<>();
apps.add(getMockAppEntry(PKG1));
@@ -265,8 +280,66 @@
}
@Test
- public void testUpdateExtraInfo_noEvents() {
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(mock(UsageEvents.class));
+ public void testLoadAllExtraInfo_multipleUsers() throws RemoteException {
+ // has work profile
+ when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{1});
+ mBridge = new AppStateNotificationBridge(mContext, mState,
+ mock(AppStateBaseBridge.Callback.class), mUsageStats, mUserManager, mBackend);
+
+ List<Event> eventsProfileOwner = new ArrayList<>();
+ for (int i = 0; i < 8; i++) {
+ Event good = new Event();
+ good.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ good.mPackage = PKG1;
+ good.mTimeStamp = i;
+ eventsProfileOwner.add(good);
+ }
+
+ List<Event> eventsProfile = new ArrayList<>();
+ for (int i = 0; i < 4; i++) {
+ Event good = new Event();
+ good.mEventType = Event.NOTIFICATION_INTERRUPTION;
+ good.mPackage = PKG1;
+ good.mTimeStamp = i;
+ eventsProfile.add(good);
+ }
+
+ UsageEvents usageEventsOwner = getUsageEvents(eventsProfileOwner);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), eq(0), anyString()))
+ .thenReturn(usageEventsOwner);
+
+ UsageEvents usageEventsProfile = getUsageEvents(eventsProfile);
+ when(mUsageStats.queryEventsForUser(anyLong(), anyLong(), eq(1), anyString()))
+ .thenReturn(usageEventsProfile);
+
+ ArrayList<AppEntry> apps = new ArrayList<>();
+ AppEntry owner = getMockAppEntry(PKG1);
+ owner.info.uid = 1;
+ apps.add(owner);
+
+ AppEntry profile = getMockAppEntry(PKG1);
+ profile.info.uid = UserHandle.PER_USER_RANGE + 1;
+ apps.add(profile);
+ when(mSession.getAllApps()).thenReturn(apps);
+
+ mBridge.loadAllExtraInfo();
+
+ assertThat(((NotificationsSentState) apps.get(0).extraInfo).sentCount).isEqualTo(8);
+ assertThat(((NotificationsSentState) apps.get(0).extraInfo).lastSent).isEqualTo(7);
+ assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentWeekly).isEqualTo(0);
+ assertThat(((NotificationsSentState) apps.get(0).extraInfo).avgSentDaily).isEqualTo(1);
+
+ assertThat(((NotificationsSentState) apps.get(1).extraInfo).sentCount).isEqualTo(4);
+ assertThat(((NotificationsSentState) apps.get(1).extraInfo).lastSent).isEqualTo(3);
+ assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentWeekly).isEqualTo(4);
+ assertThat(((NotificationsSentState) apps.get(1).extraInfo).avgSentDaily).isEqualTo(1);
+ }
+
+ @Test
+ public void testUpdateExtraInfo_noEvents() throws RemoteException {
+ when(mUsageStats.queryEventsForPackageForUser(
+ anyLong(), anyLong(), anyInt(), anyString(), anyString()))
+ .thenReturn(mock(UsageEvents.class));
AppEntry entry = getMockAppEntry(PKG1);
mBridge.updateExtraInfo(entry, "", 0);
@@ -274,7 +347,7 @@
}
@Test
- public void testUpdateExtraInfo_multipleEventsAgg() {
+ public void testUpdateExtraInfo_multipleEventsAgg() throws RemoteException {
List<Event> events = new ArrayList<>();
for (int i = 0; i < 13; i++) {
Event good = new Event();
@@ -285,7 +358,8 @@
}
UsageEvents usageEvents = getUsageEvents(events);
- when(mUsageStats.queryEvents(anyLong(), anyLong())).thenReturn(usageEvents);
+ when(mUsageStats.queryEventsForPackageForUser(
+ anyLong(), anyLong(), anyInt(), anyString(), anyString())).thenReturn(usageEvents);
AppEntry entry = getMockAppEntry(PKG1);
mBridge.updateExtraInfo(entry, "", 0);
diff --git a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
index af297c4..8943d72 100644
--- a/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
+++ b/tests/robotests/src/com/android/settings/applications/manageapplications/ManageApplicationsTest.java
@@ -16,14 +16,14 @@
package com.android.settings.applications.manageapplications;
-import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING;
-import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
-import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_ALL;
-import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
-import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;
-import static com.google.common.truth.Truth.assertThat;
+import static com.android.settings.applications.manageapplications.AppFilterRegistry
+ .FILTER_APPS_ALL;
+import static com.android.settings.applications.manageapplications.ManageApplications
+ .LIST_TYPE_MAIN;
+import static com.android.settings.applications.manageapplications.ManageApplications
+ .LIST_TYPE_NOTIFICATION;
-import static junit.framework.Assert.assertEquals;
+import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Matchers.any;
@@ -36,11 +36,14 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_DRAGGING;
+import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
+
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Looper;
-import androidx.recyclerview.widget.RecyclerView;
+import android.os.UserManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
@@ -63,6 +66,8 @@
import java.util.ArrayList;
+import androidx.recyclerview.widget.RecyclerView;
+
@RunWith(SettingsRobolectricTestRunner.class)
public class ManageApplicationsTest {
@@ -272,6 +277,10 @@
@Test
public void applicationsAdapter_onBindViewHolder_updateSwitch_notifications() {
ManageApplications manageApplications = mock(ManageApplications.class);
+ when(manageApplications.getActivity()).thenReturn(mock(Activity.class));
+ UserManager um = mock(UserManager.class);
+ when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
+ ReflectionHelpers.setField(manageApplications, "mUserManager", um);
manageApplications.mListType = LIST_TYPE_NOTIFICATION;
ApplicationViewHolder holder = mock(ApplicationViewHolder.class);
ReflectionHelpers.setField(holder, "itemView", mock(View.class));
@@ -293,6 +302,9 @@
manageApplications.mListType = LIST_TYPE_MAIN;
ApplicationViewHolder holder = mock(ApplicationViewHolder.class);
ReflectionHelpers.setField(holder, "itemView", mock(View.class));
+ UserManager um = mock(UserManager.class);
+ when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
+ ReflectionHelpers.setField(manageApplications, "mUserManager", um);
ManageApplications.ApplicationsAdapter adapter =
new ManageApplications.ApplicationsAdapter(mState,
manageApplications, mock(AppFilterItem.class),
@@ -308,6 +320,10 @@
@Test
public void sortOrderSavedOnRebuild() {
ManageApplications manageApplications = mock(ManageApplications.class);
+ when(manageApplications.getActivity()).thenReturn(mock(Activity.class));
+ UserManager um = mock(UserManager.class);
+ when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
+ ReflectionHelpers.setField(manageApplications, "mUserManager", um);
manageApplications.mListType = LIST_TYPE_NOTIFICATION;
manageApplications.mSortOrder = -1;
ManageApplications.ApplicationsAdapter adapter =
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java
index 33a00fa..bffc847 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingParentPreferenceControllerTest.java
@@ -16,14 +16,25 @@
package com.android.settings.gestures;
+import static android.provider.Settings.Secure.VOLUME_HUSH_GESTURE;
+import static android.provider.Settings.Secure.VOLUME_HUSH_MUTE;
+import static android.provider.Settings.Secure.VOLUME_HUSH_OFF;
+import static android.provider.Settings.Secure.VOLUME_HUSH_VIBRATE;
+
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
+
import static com.google.common.truth.Truth.assertThat;
+
+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.content.Context;
import android.content.res.Resources;
+import android.provider.Settings;
+import com.android.settings.R;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
@@ -41,18 +52,20 @@
private Context mContext;
private PreventRingingParentPreferenceController mController;
+ private final String VIBRATE_SUMMARY = "On (vibrate)";
+ private final String MUTE_SUMMARY = "On (mute)";
+ private final String NONE_SUMMARY = "Off";
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- when(mContext.getResources()).thenReturn(mResources);
-
+ mContext = spy(RuntimeEnvironment.application.getApplicationContext());
mController = new PreventRingingParentPreferenceController(mContext, "test_key");
}
@Test
public void testIsAvailable_configIsTrue_shouldAvailableUnSearchable() {
+ when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(true);
@@ -61,9 +74,28 @@
@Test
public void testIsAvailable_configIsFalse_shouldReturnFalse() {
+ when(mContext.getResources()).thenReturn(mResources);
when(mResources.getBoolean(
com.android.internal.R.bool.config_volumeHushGestureEnabled)).thenReturn(false);
assertThat(mController.isAvailable()).isFalse();
}
+
+ @Test
+ public void updateState_summaryUpdated() {
+ Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
+ VOLUME_HUSH_MUTE);
+ assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
+ R.string.prevent_ringing_option_mute_summary));
+
+ Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
+ VOLUME_HUSH_VIBRATE);
+ assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
+ R.string.prevent_ringing_option_vibrate_summary));
+
+ Settings.Secure.putInt(mContext.getContentResolver(), VOLUME_HUSH_GESTURE,
+ VOLUME_HUSH_OFF);
+ assertThat(mController.getSummary()).isEqualTo(mContext.getResources().getText(
+ R.string.prevent_ringing_option_none_summary));
+ }
}
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
index 833a09d..514bb58 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingPreferenceControllerTest.java
@@ -88,29 +88,6 @@
}
@Test
- public void testGetSummary_mute() {
- Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
- Settings.Secure.VOLUME_HUSH_MUTE);
- assertEquals(mContext.getString(R.string.prevent_ringing_option_mute_summary),
- mController.getSummary());
- }
-
- @Test
- public void testGetSummary_vibrate() {
- Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
- Settings.Secure.VOLUME_HUSH_VIBRATE);
- assertEquals(mContext.getString(R.string.prevent_ringing_option_vibrate_summary),
- mController.getSummary());
- }
- @Test
- public void testGetSummary_other() {
- Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,
- 7);
- assertEquals(mContext.getString(R.string.prevent_ringing_option_none_summary),
- mController.getSummary());
- }
-
- @Test
public void testUpdateState_mute() {
ListPreference pref = mock(ListPreference.class);
Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.VOLUME_HUSH_GESTURE,