Snap for 4525198 from 0590137ab2 to pi-release
Change-Id: I2fff5e424730caf84d64a0bcb5756208fed1e3b2
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2017 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"
|
|
||||||
android:background="@android:color/white"
|
|
||||||
android:clickable="true"
|
|
||||||
android:focusable="true"
|
|
||||||
android:minHeight="@dimen/dashboard_tile_minimum_height" />
|
|
||||||
@@ -6926,7 +6926,7 @@
|
|||||||
<string name="notification_group_title">Notification category group</string>
|
<string name="notification_group_title">Notification category group</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=100] Notification importance screen title -->
|
<!-- [CHAR LIMIT=100] Notification importance screen title -->
|
||||||
<string name="notification_importance_title">Importance</string>
|
<string name="notification_importance_title">Behavior</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=100 BACKUP_MESSAGE_ID=1820188704793497324] Notification Importance: unspecified importance level description -->
|
<!-- [CHAR LIMIT=100 BACKUP_MESSAGE_ID=1820188704793497324] Notification Importance: unspecified importance level description -->
|
||||||
<string name="notification_importance_unspecified">Allow sound</string>
|
<string name="notification_importance_unspecified">Allow sound</string>
|
||||||
@@ -6991,6 +6991,9 @@
|
|||||||
<!-- [CHAR LIMIT=100] Notification Importance title: high importance level title -->
|
<!-- [CHAR LIMIT=100] Notification Importance title: high importance level title -->
|
||||||
<string name="notification_channel_summary_high">Urgent importance</string>
|
<string name="notification_channel_summary_high">Urgent importance</string>
|
||||||
|
|
||||||
|
<!-- [CHAR LIMIT=100] Label for on/off toggle -->
|
||||||
|
<string name="notification_switch_label">Show notifications</string>
|
||||||
|
|
||||||
<!-- Default Apps > Default notification assistant -->
|
<!-- Default Apps > Default notification assistant -->
|
||||||
<string name="default_notification_assistant">Notification assistant</string>
|
<string name="default_notification_assistant">Notification assistant</string>
|
||||||
|
|
||||||
@@ -7087,13 +7090,13 @@
|
|||||||
<string name="loading_notification_apps">Loading apps...</string>
|
<string name="loading_notification_apps">Loading apps...</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] Text appearing when app notifications are off -->
|
<!-- [CHAR LIMIT=NONE] Text appearing when app notifications are off -->
|
||||||
<string name="app_notifications_off_desc">Android is blocking this app\'s notifications from appearing on this device</string>
|
<string name="app_notifications_off_desc">At your request, Android is blocking this app\'s notifications from appearing on this device</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] Text appearing when channel notifications are off -->
|
<!-- [CHAR LIMIT=NONE] Text appearing when channel notifications are off -->
|
||||||
<string name="channel_notifications_off_desc">Android is blocking this category of notifications from appearing on this device</string>
|
<string name="channel_notifications_off_desc">At your request, Android is blocking this category of notifications from appearing on this device</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] Text appearing when channel group notifications are off -->
|
<!-- [CHAR LIMIT=NONE] Text appearing when channel group notifications are off -->
|
||||||
<string name="channel_group_notifications_off_desc">Android is blocking this group of notifications from appearing on this device</string>
|
<string name="channel_group_notifications_off_desc">At your request, Android is blocking this group of notifications from appearing on this device</string>
|
||||||
|
|
||||||
<!-- [CHAR LIMIT=NONE] App notification settings: channels title -->
|
<!-- [CHAR LIMIT=NONE] App notification settings: channels title -->
|
||||||
<string name="notification_channels">Categories</string>
|
<string name="notification_channels">Categories</string>
|
||||||
|
|||||||
@@ -15,7 +15,8 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto" >
|
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||||
|
settings:initialExpandedChildrenCount="3">
|
||||||
|
|
||||||
<com.android.settings.applications.LayoutPreference
|
<com.android.settings.applications.LayoutPreference
|
||||||
android:key="pref_app_header"
|
android:key="pref_app_header"
|
||||||
|
|||||||
@@ -19,20 +19,15 @@
|
|||||||
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
<com.android.settings.widget.RadioButtonPreference
|
||||||
android:key="importance_high"
|
android:key="importance_high"
|
||||||
android:title="@string/notification_importance_high_title"
|
android:title="@string/notification_importance_high" />
|
||||||
android:summary="@string/notification_importance_high"
|
|
||||||
/>
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
<com.android.settings.widget.RadioButtonPreference
|
||||||
android:key="importance_default"
|
android:key="importance_default"
|
||||||
android:title="@string/notification_importance_default_title"
|
android:title="@string/notification_importance_default" />
|
||||||
android:summary="@string/notification_importance_default" />
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
<com.android.settings.widget.RadioButtonPreference
|
||||||
android:key="importance_low"
|
android:key="importance_low"
|
||||||
android:title="@string/notification_importance_low_title"
|
android:title="@string/notification_importance_low" />
|
||||||
android:summary="@string/notification_importance_low" />
|
|
||||||
<com.android.settings.widget.RadioButtonPreference
|
<com.android.settings.widget.RadioButtonPreference
|
||||||
android:key="importance_min"
|
android:key="importance_min"
|
||||||
android:title="@string/notification_importance_min_title"
|
android:title="@string/notification_importance_min" />
|
||||||
android:summary="@string/notification_importance_min" />
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
|||||||
@@ -63,8 +63,7 @@
|
|||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<Preference android:key="sim_lock_settings"
|
<Preference android:key="sim_lock_settings"
|
||||||
android:title="@string/sim_lock_settings_category"
|
android:title="@string/sim_lock_settings_category">
|
||||||
android:persistent="false">
|
|
||||||
|
|
||||||
<intent android:action="android.intent.action.MAIN"
|
<intent android:action="android.intent.action.MAIN"
|
||||||
android:targetPackage="com.android.settings"
|
android:targetPackage="com.android.settings"
|
||||||
@@ -86,7 +85,7 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="screen_pinning_settings"
|
android:key="screen_pinning_settings"
|
||||||
android:title="@string/screen_pinning_title"
|
android:title="@string/screen_pinning_title"
|
||||||
android:summary="@string/switch_off_text"
|
android:summary="@string/summary_placeholder"
|
||||||
android:fragment="com.android.settings.security.ScreenPinningSettings"/>
|
android:fragment="com.android.settings.security.ScreenPinningSettings"/>
|
||||||
|
|
||||||
<Preference android:key="security_misc_usage_access"
|
<Preference android:key="security_misc_usage_access"
|
||||||
|
|||||||
@@ -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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<optional-steps>
|
|
||||||
<step category="com.android.settings.suggested.category.DEFERRED_SETUP"
|
|
||||||
exclusive="true" />
|
|
||||||
<step category="com.android.settings.suggested.category.FIRST_IMPRESSION"
|
|
||||||
exclusiveExpireDays="14"
|
|
||||||
exclusive="true"
|
|
||||||
multiple="true" />
|
|
||||||
<step category="com.android.settings.suggested.category.LOCK_SCREEN" />
|
|
||||||
<step category="com.android.settings.suggested.category.TRUST_AGENT" />
|
|
||||||
<step category="com.android.settings.suggested.category.EMAIL" />
|
|
||||||
<step category="com.android.settings.suggested.category.PARTNER_ACCOUNT"
|
|
||||||
multiple="true" />
|
|
||||||
<step category="com.android.settings.suggested.category.GESTURE" />
|
|
||||||
<step category="com.android.settings.suggested.category.HOTWORD" />
|
|
||||||
<step category="com.android.settings.suggested.category.DEFAULT"
|
|
||||||
multiple="true" />
|
|
||||||
<step category="com.android.settings.suggested.category.SETTINGS_ONLY"
|
|
||||||
multiple="true" />
|
|
||||||
</optional-steps>
|
|
||||||
@@ -21,7 +21,6 @@ package com.android.settings.core;
|
|||||||
*/
|
*/
|
||||||
public class FeatureFlags {
|
public class FeatureFlags {
|
||||||
public static final String SEARCH_V2 = "settings_search_v2";
|
public static final String SEARCH_V2 = "settings_search_v2";
|
||||||
public static final String SUGGESTIONS_V2 = "new_settings_suggestion";
|
|
||||||
public static final String APP_INFO_V2 = "settings_app_info_v2";
|
public static final String APP_INFO_V2 = "settings_app_info_v2";
|
||||||
public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
|
public static final String CONNECTED_DEVICE_V2 = "settings_connected_device_v2";
|
||||||
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
|
public static final String BATTERY_SETTINGS_V2 = "settings_battery_v2";
|
||||||
|
|||||||
@@ -14,8 +14,8 @@
|
|||||||
package com.android.settings.core;
|
package com.android.settings.core;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.TwoStatePreference;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class that consolidates logic for updating toggle controllers.
|
* Abstract class that consolidates logic for updating toggle controllers.
|
||||||
@@ -45,7 +45,7 @@ public abstract class TogglePreferenceController extends BasePreferenceControlle
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void updateState(Preference preference) {
|
public final void updateState(Preference preference) {
|
||||||
((SwitchPreference) preference).setChecked(isChecked());
|
((TwoStatePreference) preference).setChecked(isChecked());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -39,7 +39,6 @@ public class MetricsFeatureProvider {
|
|||||||
|
|
||||||
protected void installLogWriters() {
|
protected void installLogWriters() {
|
||||||
mLoggerWriters.add(new EventLogWriter());
|
mLoggerWriters.add(new EventLogWriter());
|
||||||
mLoggerWriters.add(new SettingSuggestionsLogWriter());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void visible(Context context, int source, int category) {
|
public void visible(Context context, int source, int category) {
|
||||||
|
|||||||
@@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.core.instrumentation;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
||||||
import com.android.settings.dashboard.suggestions.EventStore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link LogWriter} that writes setting suggestion related logs.
|
|
||||||
*/
|
|
||||||
public class SettingSuggestionsLogWriter implements LogWriter {
|
|
||||||
|
|
||||||
private EventStore mEventStore;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visible(Context context, int source, int category) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void hidden(Context context, int category) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(Context context, int category, Pair<Integer, Object>... taggedData) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void actionWithSource(Context context, int source, int category) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(int category, int value, Pair<Integer, Object>... taggedData) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(int category, boolean value, Pair<Integer, Object>... taggedData) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(Context context, int category, int value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(Context context, int category, boolean value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void action(Context context, int category, String pkg,
|
|
||||||
Pair<Integer, Object>... taggedData) {
|
|
||||||
if (mEventStore == null) {
|
|
||||||
mEventStore = new EventStore(context);
|
|
||||||
}
|
|
||||||
switch (category) {
|
|
||||||
case MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION:
|
|
||||||
mEventStore.writeEvent(pkg, EventStore.EVENT_SHOWN);
|
|
||||||
break;
|
|
||||||
case MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION:
|
|
||||||
mEventStore.writeEvent(pkg, EventStore.EVENT_DISMISSED);
|
|
||||||
break;
|
|
||||||
case MetricsEvent.ACTION_SETTINGS_SUGGESTION:
|
|
||||||
mEventStore.writeEvent(pkg, EventStore.EVENT_CLICKED);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void count(Context context, String name, int value) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void histogram(Context context, String name, int bucket) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -52,7 +52,6 @@ import com.android.settings.overlay.FeatureFactory;
|
|||||||
import com.android.settingslib.Utils;
|
import com.android.settingslib.Utils;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -61,7 +60,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
implements SummaryLoader.SummaryConsumer {
|
implements SummaryLoader.SummaryConsumer {
|
||||||
public static final String TAG = "DashboardAdapter";
|
public static final String TAG = "DashboardAdapter";
|
||||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||||
private static final String STATE_SUGGESTION_LIST_V2 = "suggestion_list_v2";
|
|
||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||||
|
|
||||||
@@ -69,8 +67,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
static final String STATE_SUGGESTION_CONDITION_MODE = "suggestion_condition_mode";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final int SUGGESTION_CONDITION_HEADER_POSITION = 0;
|
static final int SUGGESTION_CONDITION_HEADER_POSITION = 0;
|
||||||
@VisibleForTesting
|
|
||||||
static final int MAX_SUGGESTION_TO_SHOW = 5;
|
|
||||||
|
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
@@ -80,7 +76,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
private final ArrayList<String> mSuggestionsShownLogged;
|
private final ArrayList<String> mSuggestionsShownLogged;
|
||||||
private boolean mFirstFrameDrawn;
|
private boolean mFirstFrameDrawn;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private SuggestionParser mSuggestionParser;
|
|
||||||
private SuggestionAdapter mSuggestionAdapter;
|
private SuggestionAdapter mSuggestionAdapter;
|
||||||
private SuggestionDismissController mSuggestionDismissHandler;
|
private SuggestionDismissController mSuggestionDismissHandler;
|
||||||
private SuggestionDismissController.Callback mCallback;
|
private SuggestionDismissController.Callback mCallback;
|
||||||
@@ -97,13 +92,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
};
|
};
|
||||||
|
|
||||||
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
||||||
List<Condition> conditions, SuggestionParser suggestionParser,
|
List<Condition> conditions, SuggestionControllerMixin suggestionControllerMixin,
|
||||||
SuggestionControllerMixin suggestionControllerMixin,
|
|
||||||
SuggestionDismissController.Callback callback) {
|
SuggestionDismissController.Callback callback) {
|
||||||
|
|
||||||
// @deprecated In favor of suggestionsV2 below.
|
List<Suggestion> suggestions = null;
|
||||||
List<Tile> suggestions = null;
|
|
||||||
List<Suggestion> suggestionsV2 = null;
|
|
||||||
DashboardCategory category = null;
|
DashboardCategory category = null;
|
||||||
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
||||||
|
|
||||||
@@ -113,14 +105,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
||||||
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
|
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
|
||||||
mCache = new IconCache(context);
|
mCache = new IconCache(context);
|
||||||
mSuggestionParser = suggestionParser;
|
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||||
suggestionsV2 = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST_V2);
|
|
||||||
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
|
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
|
||||||
suggestionConditionMode = savedInstanceState.getInt(
|
suggestionConditionMode = savedInstanceState.getInt(
|
||||||
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
||||||
@@ -133,37 +123,15 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
mDashboardData = new DashboardData.Builder()
|
mDashboardData = new DashboardData.Builder()
|
||||||
.setConditions(conditions)
|
.setConditions(conditions)
|
||||||
.setSuggestions(suggestions)
|
.setSuggestions(suggestions)
|
||||||
.setSuggestionsV2(suggestionsV2)
|
|
||||||
.setCategory(category)
|
.setCategory(category)
|
||||||
.setSuggestionConditionMode(suggestionConditionMode)
|
.setSuggestionConditionMode(suggestionConditionMode)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tile> getSuggestions() {
|
public void setSuggestions(List<Suggestion> data) {
|
||||||
return mDashboardData.getSuggestions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #setCategory(DashboardCategory)} and
|
|
||||||
* {@link #setSuggestionsV2(List)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void setCategoriesAndSuggestions(DashboardCategory category, List<Tile> suggestions) {
|
|
||||||
tintIcons(category, suggestions);
|
|
||||||
|
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
.setSuggestions(suggestions.subList(0,
|
.setSuggestions(data)
|
||||||
Math.min(suggestions.size(), MAX_SUGGESTION_TO_SHOW)))
|
|
||||||
.setCategory(category)
|
|
||||||
.build();
|
|
||||||
notifyDashboardDataChanged(prevData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSuggestionsV2(List<Suggestion> data) {
|
|
||||||
final DashboardData prevData = mDashboardData;
|
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
|
||||||
.setSuggestionsV2(data)
|
|
||||||
.build();
|
.build();
|
||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
@@ -187,30 +155,8 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public void onSuggestionDismissed(Tile suggestion) {
|
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
|
||||||
if (suggestions == null || suggestions.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (suggestions.size() == 1) {
|
|
||||||
// The only suggestion is dismissed, and the the empty suggestion container will
|
|
||||||
// remain as the dashboard item. Need to refresh the dashboard list.
|
|
||||||
final DashboardData prevData = mDashboardData;
|
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
|
||||||
.setSuggestions(null)
|
|
||||||
.build();
|
|
||||||
notifyDashboardDataChanged(prevData);
|
|
||||||
} else {
|
|
||||||
mSuggestionAdapter.removeSuggestion(suggestion);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSuggestionDismissed(Suggestion suggestion) {
|
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||||
final List<Suggestion> list = mDashboardData.getSuggestionsV2();
|
final List<Suggestion> list = mDashboardData.getSuggestions();
|
||||||
if (list == null || list.size() == 0) {
|
if (list == null || list.size() == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -219,7 +165,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
// remain as the dashboard item. Need to refresh the dashboard list.
|
// remain as the dashboard item. Need to refresh the dashboard list.
|
||||||
final DashboardData prevData = mDashboardData;
|
final DashboardData prevData = mDashboardData;
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
mDashboardData = new DashboardData.Builder(prevData)
|
||||||
.setSuggestionsV2(null)
|
.setSuggestions(null)
|
||||||
.build();
|
.build();
|
||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
} else {
|
} else {
|
||||||
@@ -309,18 +255,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
return mDashboardData.getItemEntityById(itemId);
|
return mDashboardData.getItemEntityById(itemId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Suggestion getSuggestion(int position) {
|
||||||
* @deprecated in favor of {@link #getSuggestionV2(int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Tile getSuggestion(int position) {
|
|
||||||
return mSuggestionAdapter.getSuggestion(position);
|
return mSuggestionAdapter.getSuggestion(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Suggestion getSuggestionV2(int position) {
|
|
||||||
return mSuggestionAdapter.getSuggestionsV2(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void notifyDashboardDataChanged(DashboardData prevData) {
|
void notifyDashboardDataChanged(DashboardData prevData) {
|
||||||
if (mFirstFrameDrawn && prevData != null) {
|
if (mFirstFrameDrawn && prevData != null) {
|
||||||
@@ -422,26 +360,17 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
int position) {
|
int position) {
|
||||||
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
||||||
// header anymore.
|
// header anymore.
|
||||||
final List<Suggestion> suggestionsV2 = mDashboardData.getSuggestionsV2();
|
final List<Suggestion> suggestions = mDashboardData.getSuggestions();
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
|
||||||
|
|
||||||
boolean conditionOnly = true;
|
boolean conditionOnly = true;
|
||||||
if (position == SUGGESTION_CONDITION_HEADER_POSITION) {
|
if (position == SUGGESTION_CONDITION_HEADER_POSITION) {
|
||||||
if (suggestions != null && suggestions.size() > 0) {
|
if (suggestions != null && suggestions.size() > 0) {
|
||||||
conditionOnly = false;
|
conditionOnly = false;
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
(List<Tile>) mDashboardData.getItemEntityByPosition(position),
|
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
|
||||||
null, mSuggestionsShownLogged);
|
|
||||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
|
||||||
holder.data, mSuggestionControllerMixin, mSuggestionParser, mCallback);
|
|
||||||
holder.data.setAdapter(mSuggestionAdapter);
|
|
||||||
} else if (suggestionsV2 != null && suggestionsV2.size() > 0) {
|
|
||||||
conditionOnly = false;
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
|
||||||
null, (List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
|
|
||||||
mSuggestionsShownLogged);
|
mSuggestionsShownLogged);
|
||||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||||
holder.data, mSuggestionControllerMixin, null /* parser */, mCallback);
|
holder.data, mSuggestionControllerMixin, mCallback);
|
||||||
holder.data.setAdapter(mSuggestionAdapter);
|
holder.data.setAdapter(mSuggestionAdapter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -494,14 +423,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
|
|
||||||
void onSaveInstanceState(Bundle outState) {
|
void onSaveInstanceState(Bundle outState) {
|
||||||
final DashboardCategory category = mDashboardData.getCategory();
|
final DashboardCategory category = mDashboardData.getCategory();
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
final List<Suggestion> suggestions = mDashboardData.getSuggestions();
|
||||||
final List<Suggestion> suggestionV2 = mDashboardData.getSuggestionsV2();
|
|
||||||
if (suggestions != null) {
|
if (suggestions != null) {
|
||||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
|
outState.putParcelableArrayList(STATE_SUGGESTION_LIST,
|
||||||
}
|
new ArrayList<>(suggestions));
|
||||||
if (suggestionV2 != null) {
|
|
||||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST_V2,
|
|
||||||
new ArrayList<>(suggestionV2));
|
|
||||||
}
|
}
|
||||||
if (category != null) {
|
if (category != null) {
|
||||||
outState.putParcelable(STATE_CATEGORY_LIST, category);
|
outState.putParcelable(STATE_CATEGORY_LIST, category);
|
||||||
|
|||||||
@@ -69,16 +69,14 @@ public class DashboardData {
|
|||||||
private final List<Item> mItems;
|
private final List<Item> mItems;
|
||||||
private final DashboardCategory mCategory;
|
private final DashboardCategory mCategory;
|
||||||
private final List<Condition> mConditions;
|
private final List<Condition> mConditions;
|
||||||
private final List<Tile> mSuggestions;
|
private final List<Suggestion> mSuggestions;
|
||||||
private final List<Suggestion> mSuggestionsV2;
|
|
||||||
@HeaderMode
|
@HeaderMode
|
||||||
private final int mSuggestionConditionMode;
|
private final int mSuggestionConditionMode;
|
||||||
|
|
||||||
private DashboardData(Builder builder) {
|
private DashboardData(Builder builder) {
|
||||||
mCategory = builder.mCategory;
|
mCategory = builder.mCategory;
|
||||||
mConditions = builder.mConditions;
|
mConditions = builder.mConditions;
|
||||||
mSuggestions = builder.mSuggestions;
|
mSuggestions = builder.mSuggestionsV2;
|
||||||
mSuggestionsV2 = builder.mSuggestionsV2;
|
|
||||||
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
||||||
|
|
||||||
mItems = new ArrayList<>();
|
mItems = new ArrayList<>();
|
||||||
@@ -123,14 +121,10 @@ public class DashboardData {
|
|||||||
return mConditions;
|
return mConditions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Tile> getSuggestions() {
|
public List<Suggestion> getSuggestions() {
|
||||||
return mSuggestions;
|
return mSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Suggestion> getSuggestionsV2() {
|
|
||||||
return mSuggestionsV2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSuggestionConditionMode() {
|
public int getSuggestionConditionMode() {
|
||||||
return mSuggestionConditionMode;
|
return mSuggestionConditionMode;
|
||||||
}
|
}
|
||||||
@@ -197,22 +191,15 @@ public class DashboardData {
|
|||||||
* and mIsShowingAll, mSuggestionConditionMode flag.
|
* and mIsShowingAll, mSuggestionConditionMode flag.
|
||||||
*/
|
*/
|
||||||
private void buildItemsData() {
|
private void buildItemsData() {
|
||||||
final boolean useSuggestionV2 = mSuggestionsV2 != null;
|
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
||||||
final boolean hasSuggestions = useSuggestionV2
|
|
||||||
? sizeOf(mSuggestionsV2) > 0
|
|
||||||
: sizeOf(mSuggestions) > 0;
|
|
||||||
final List<Condition> conditions = getConditionsToShow(mConditions);
|
final List<Condition> conditions = getConditionsToShow(mConditions);
|
||||||
final boolean hasConditions = sizeOf(conditions) > 0;
|
final boolean hasConditions = sizeOf(conditions) > 0;
|
||||||
|
|
||||||
final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
|
final List<Suggestion> suggestions = getSuggestionsToShow(mSuggestions);
|
||||||
final List<Suggestion> suggestionsV2 = getSuggestionsV2ToShow(mSuggestionsV2);
|
|
||||||
|
|
||||||
final int hiddenSuggestion;
|
final int hiddenSuggestion = hasSuggestions
|
||||||
if (useSuggestionV2) {
|
? sizeOf(mSuggestions) - sizeOf(suggestions)
|
||||||
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestionsV2) - sizeOf(suggestionsV2) : 0;
|
: 0;
|
||||||
} else {
|
|
||||||
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
final boolean hasSuggestionAndCollapsed = hasSuggestions
|
final boolean hasSuggestionAndCollapsed = hasSuggestions
|
||||||
&& mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
|
&& mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
|
||||||
@@ -231,15 +218,8 @@ public class DashboardData {
|
|||||||
R.layout.suggestion_condition_header,
|
R.layout.suggestion_condition_header,
|
||||||
STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
|
STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
|
||||||
|
|
||||||
if (useSuggestionV2) {
|
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
||||||
addToItemList(suggestionsV2, R.layout.suggestion_condition_container,
|
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
||||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestionsV2) > 0);
|
|
||||||
} else {
|
|
||||||
/* Suggestion container. This is the card view that contains the list of suggestions.
|
|
||||||
* This will be added whenever the suggestion list is not empty */
|
|
||||||
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
|
||||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Second suggestion/condition header. This will be added when there is at least one
|
/* Second suggestion/condition header. This will be added when there is at least one
|
||||||
* suggestion or condition that is not currently displayed, and the user can expand the
|
* suggestion or condition that is not currently displayed, and the user can expand the
|
||||||
@@ -296,22 +276,7 @@ public class DashboardData {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private List<Suggestion> getSuggestionsToShow(List<Suggestion> suggestions) {
|
||||||
* @deprecated in favor of {@link #getSuggestionsV2ToShow}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private List<Tile> getSuggestionsToShow(List<Tile> suggestions) {
|
|
||||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (mSuggestionConditionMode != HEADER_MODE_DEFAULT
|
|
||||||
|| suggestions.size() <= DEFAULT_SUGGESTION_COUNT) {
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Suggestion> getSuggestionsV2ToShow(List<Suggestion> suggestions) {
|
|
||||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -333,11 +298,6 @@ public class DashboardData {
|
|||||||
|
|
||||||
private DashboardCategory mCategory;
|
private DashboardCategory mCategory;
|
||||||
private List<Condition> mConditions;
|
private List<Condition> mConditions;
|
||||||
/**
|
|
||||||
* @deprecated in favor of SuggestionList
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private List<Tile> mSuggestions;
|
|
||||||
private List<Suggestion> mSuggestionsV2;
|
private List<Suggestion> mSuggestionsV2;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
@@ -346,8 +306,7 @@ public class DashboardData {
|
|||||||
public Builder(DashboardData dashboardData) {
|
public Builder(DashboardData dashboardData) {
|
||||||
mCategory = dashboardData.mCategory;
|
mCategory = dashboardData.mCategory;
|
||||||
mConditions = dashboardData.mConditions;
|
mConditions = dashboardData.mConditions;
|
||||||
mSuggestions = dashboardData.mSuggestions;
|
mSuggestionsV2 = dashboardData.mSuggestions;
|
||||||
mSuggestionsV2 = dashboardData.mSuggestionsV2;
|
|
||||||
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,16 +320,7 @@ public class DashboardData {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public Builder setSuggestions(List<Suggestion> suggestions) {
|
||||||
* @deprecated in favor of {@link #setSuggestionsV2(List)})}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public Builder setSuggestions(List<Tile> suggestions) {
|
|
||||||
this.mSuggestions = suggestions;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder setSuggestionsV2(List<Suggestion> suggestions) {
|
|
||||||
this.mSuggestionsV2 = suggestions;
|
this.mSuggestionsV2 = suggestions;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.settings.dashboard;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.LoaderManager;
|
import android.app.LoaderManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
@@ -41,19 +40,14 @@ import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
|||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settings.widget.ActionBarShadowController;
|
import com.android.settings.widget.ActionBarShadowController;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity.CategoryListener;
|
import com.android.settingslib.drawer.SettingsDrawerActivity.CategoryListener;
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
import com.android.settingslib.suggestions.SuggestionList;
|
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
import com.android.settingslib.utils.ThreadUtils;
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DashboardSummary extends InstrumentedFragment
|
public class DashboardSummary extends InstrumentedFragment
|
||||||
@@ -73,11 +67,9 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
private DashboardAdapter mAdapter;
|
private DashboardAdapter mAdapter;
|
||||||
private SummaryLoader mSummaryLoader;
|
private SummaryLoader mSummaryLoader;
|
||||||
private ConditionManager mConditionManager;
|
private ConditionManager mConditionManager;
|
||||||
private SuggestionParser mSuggestionParser;
|
|
||||||
private LinearLayoutManager mLayoutManager;
|
private LinearLayoutManager mLayoutManager;
|
||||||
private SuggestionControllerMixin mSuggestionControllerMixin;
|
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||||
private SuggestionFeatureProvider mSuggestionFeatureProvider;
|
|
||||||
private boolean isOnCategoriesChangedCalled;
|
private boolean isOnCategoriesChangedCalled;
|
||||||
private boolean mOnConditionsChangedCalled;
|
private boolean mOnConditionsChangedCalled;
|
||||||
|
|
||||||
@@ -92,13 +84,9 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
|
Log.d(TAG, "Creating SuggestionControllerMixin");
|
||||||
.getSuggestionFeatureProvider(context);
|
mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
|
||||||
if (mSuggestionFeatureProvider.isSuggestionV2Enabled(context)) {
|
getLifecycle());
|
||||||
Log.d(TAG, "Suggestion v2 is enabled, creating SuggestionControllerMixin");
|
|
||||||
mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
|
|
||||||
getLifecycle());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -121,10 +109,6 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
|
|
||||||
mConditionManager = ConditionManager.get(activity, false);
|
mConditionManager = ConditionManager.get(activity, false);
|
||||||
getLifecycle().addObserver(mConditionManager);
|
getLifecycle().addObserver(mConditionManager);
|
||||||
if (mSuggestionFeatureProvider.isSuggestionEnabled(activity)) {
|
|
||||||
mSuggestionParser = new SuggestionParser(activity,
|
|
||||||
mSuggestionFeatureProvider.getSharedPrefs(activity), R.xml.suggestion_ordering);
|
|
||||||
}
|
|
||||||
if (DEBUG_TIMING) {
|
if (DEBUG_TIMING) {
|
||||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
}
|
}
|
||||||
@@ -211,8 +195,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mDashboard.setHasFixedSize(true);
|
mDashboard.setHasFixedSize(true);
|
||||||
mDashboard.setListener(this);
|
mDashboard.setListener(this);
|
||||||
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
|
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
|
||||||
mSuggestionParser, mSuggestionControllerMixin,
|
mSuggestionControllerMixin, this /* SuggestionDismissController.Callback */);
|
||||||
this /* SuggestionDismissController.Callback */);
|
|
||||||
mDashboard.setAdapter(mAdapter);
|
mDashboard.setAdapter(mAdapter);
|
||||||
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
||||||
mSummaryLoader.setSummaryConsumer(mAdapter);
|
mSummaryLoader.setSummaryConsumer(mAdapter);
|
||||||
@@ -228,16 +211,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void rebuildUI() {
|
void rebuildUI() {
|
||||||
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
|
ThreadUtils.postOnBackgroundThread(() -> updateCategory());
|
||||||
Log.d(TAG, "Suggestion v1 feature is disabled, skipping suggestion v1");
|
|
||||||
ThreadUtils.postOnBackgroundThread(() -> updateCategory());
|
|
||||||
} else {
|
|
||||||
new SuggestionLoader().execute();
|
|
||||||
// Set categories on their own if loading suggestions takes too long.
|
|
||||||
mHandler.postDelayed(() -> {
|
|
||||||
updateCategory();
|
|
||||||
}, MAX_WAIT_MILLIS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -274,19 +248,9 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Suggestion getSuggestionAt(int position) {
|
public Suggestion getSuggestionAt(int position) {
|
||||||
return mAdapter.getSuggestionV2(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tile getSuggestionForPosition(int position) {
|
|
||||||
return mAdapter.getSuggestion(position);
|
return mAdapter.getSuggestion(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuggestionDismissed(Tile suggestion) {
|
|
||||||
mAdapter.onSuggestionDismissed(suggestion);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuggestionDismissed(Suggestion suggestion) {
|
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||||
mAdapter.onSuggestionDismissed(suggestion);
|
mAdapter.onSuggestionDismissed(suggestion);
|
||||||
@@ -295,7 +259,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onSuggestionReady(List<Suggestion> suggestions) {
|
public void onSuggestionReady(List<Suggestion> suggestions) {
|
||||||
mStagingSuggestions = suggestions;
|
mStagingSuggestions = suggestions;
|
||||||
mAdapter.setSuggestionsV2(suggestions);
|
mAdapter.setSuggestions(suggestions);
|
||||||
if (mStagingCategory != null) {
|
if (mStagingCategory != null) {
|
||||||
Log.d(TAG, "Category has loaded, setting category from suggestionReady");
|
Log.d(TAG, "Category has loaded, setting category from suggestionReady");
|
||||||
mHandler.removeCallbacksAndMessages(null);
|
mHandler.removeCallbacksAndMessages(null);
|
||||||
@@ -303,49 +267,6 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #mSuggestionControllerMixin}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
|
||||||
@Override
|
|
||||||
protected List<Tile> doInBackground(Void... params) {
|
|
||||||
final Context context = getContext();
|
|
||||||
boolean isSmartSuggestionEnabled =
|
|
||||||
mSuggestionFeatureProvider.isSmartSuggestionEnabled(context);
|
|
||||||
final SuggestionList sl = mSuggestionParser.getSuggestions(isSmartSuggestionEnabled);
|
|
||||||
final List<Tile> suggestions = sl.getSuggestions();
|
|
||||||
|
|
||||||
if (isSmartSuggestionEnabled) {
|
|
||||||
List<String> suggestionIds = new ArrayList<>(suggestions.size());
|
|
||||||
for (Tile suggestion : suggestions) {
|
|
||||||
suggestionIds.add(mSuggestionFeatureProvider.getSuggestionIdentifier(
|
|
||||||
context, suggestion));
|
|
||||||
}
|
|
||||||
// TODO: create a Suggestion class to maintain the id and other info
|
|
||||||
mSuggestionFeatureProvider.rankSuggestions(suggestions, suggestionIds);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < suggestions.size(); i++) {
|
|
||||||
Tile suggestion = suggestions.get(i);
|
|
||||||
if (mSuggestionFeatureProvider.isSuggestionComplete(context,
|
|
||||||
suggestion.intent.getComponent())) {
|
|
||||||
suggestions.remove(i--);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (sl.isExclusiveSuggestionCategory()) {
|
|
||||||
mSuggestionFeatureProvider.filterExclusiveSuggestions(suggestions);
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(List<Tile> tiles) {
|
|
||||||
// tell handler that suggestions were loaded quickly enough
|
|
||||||
mHandler.removeCallbacksAndMessages(null);
|
|
||||||
updateCategoryAndSuggestion(tiles);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
@WorkerThread
|
||||||
void updateCategory() {
|
void updateCategory() {
|
||||||
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
||||||
@@ -356,7 +277,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
|
Log.d(TAG, "Suggestion has loaded, setting suggestion/category");
|
||||||
ThreadUtils.postOnMainThread(() -> {
|
ThreadUtils.postOnMainThread(() -> {
|
||||||
if (mStagingSuggestions != null) {
|
if (mStagingSuggestions != null) {
|
||||||
mAdapter.setSuggestionsV2(mStagingSuggestions);
|
mAdapter.setSuggestions(mStagingSuggestions);
|
||||||
}
|
}
|
||||||
mAdapter.setCategory(mStagingCategory);
|
mAdapter.setCategory(mStagingCategory);
|
||||||
});
|
});
|
||||||
@@ -365,26 +286,4 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
|
mHandler.postDelayed(() -> mAdapter.setCategory(mStagingCategory), MAX_WAIT_MILLIS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #mSuggestionControllerMixin}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
@VisibleForTesting
|
|
||||||
void updateCategoryAndSuggestion(List<Tile> suggestions) {
|
|
||||||
final Activity activity = getActivity();
|
|
||||||
if (activity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
|
||||||
CategoryKey.CATEGORY_HOMEPAGE);
|
|
||||||
mSummaryLoader.updateSummaryToCache(category);
|
|
||||||
if (suggestions != null) {
|
|
||||||
mAdapter.setCategoriesAndSuggestions(category, suggestions);
|
|
||||||
} else {
|
|
||||||
mAdapter.setCategory(category);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores suggestion related statistics.
|
|
||||||
*/
|
|
||||||
public class EventStore {
|
|
||||||
|
|
||||||
public static final String TAG = "SuggestionEventStore";
|
|
||||||
|
|
||||||
public static final String EVENT_SHOWN = "shown";
|
|
||||||
public static final String EVENT_DISMISSED = "dismissed";
|
|
||||||
public static final String EVENT_CLICKED = "clicked";
|
|
||||||
public static final String METRIC_LAST_EVENT_TIME = "last_event_time";
|
|
||||||
public static final String METRIC_COUNT = "count";
|
|
||||||
|
|
||||||
private static final Set<String> EVENTS = new HashSet<String>(
|
|
||||||
Arrays.asList(new String[] {EVENT_SHOWN, EVENT_DISMISSED, EVENT_CLICKED}));
|
|
||||||
private static final Set<String> METRICS = new HashSet<String>(
|
|
||||||
Arrays.asList(new String[] {METRIC_LAST_EVENT_TIME, METRIC_COUNT}));
|
|
||||||
|
|
||||||
private final SharedPreferences mSharedPrefs;
|
|
||||||
|
|
||||||
public EventStore(Context context) {
|
|
||||||
mSharedPrefs = context.getSharedPreferences(TAG, Context.MODE_PRIVATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes individual log events.
|
|
||||||
* @param pkgName: Package for which this event is reported.
|
|
||||||
* @param eventType: Type of event (one of {@link #EVENTS}).
|
|
||||||
*/
|
|
||||||
public void writeEvent(String pkgName, String eventType) {
|
|
||||||
if (!EVENTS.contains(eventType)) {
|
|
||||||
Log.w(TAG, "Reported event type " + eventType + " is not a valid type!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String lastTimePrefKey = getPrefKey(pkgName, eventType, METRIC_LAST_EVENT_TIME);
|
|
||||||
final String countPrefKey = getPrefKey(pkgName, eventType, METRIC_COUNT);
|
|
||||||
writePref(lastTimePrefKey, System.currentTimeMillis());
|
|
||||||
writePref(countPrefKey, readPref(countPrefKey, (long) 0) + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reads metric of the the reported events (e.g., counts).
|
|
||||||
* @param pkgName: Package for which this metric is queried.
|
|
||||||
* @param eventType: Type of event (one of {@link #EVENTS}).
|
|
||||||
* @param metricType: Type of the queried metric (one of {@link #METRICS}).
|
|
||||||
* @return the corresponding metric.
|
|
||||||
*/
|
|
||||||
public long readMetric(String pkgName, String eventType, String metricType) {
|
|
||||||
if (!EVENTS.contains(eventType)) {
|
|
||||||
Log.w(TAG, "Reported event type " + eventType + " is not a valid event!");
|
|
||||||
return 0;
|
|
||||||
} else if (!METRICS.contains(metricType)) {
|
|
||||||
Log.w(TAG, "Required stat type + " + metricType + " is not a valid stat!");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return readPref(getPrefKey(pkgName, eventType, metricType), (long) 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void writePref(String prefKey, long value) {
|
|
||||||
mSharedPrefs.edit().putLong(prefKey, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
private long readPref(String prefKey, Long defaultValue) {
|
|
||||||
return mSharedPrefs.getLong(prefKey, defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getPrefKey(String pkgName, String eventType, String statType) {
|
|
||||||
return new StringBuilder()
|
|
||||||
.append("setting_suggestion_")
|
|
||||||
.append(pkgName)
|
|
||||||
.append("_")
|
|
||||||
.append(eventType)
|
|
||||||
.append("_")
|
|
||||||
.append(statType)
|
|
||||||
.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -27,12 +27,10 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
|
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
|
||||||
import com.android.settings.dashboard.DashboardAdapter.IconCache;
|
import com.android.settings.dashboard.DashboardAdapter.IconCache;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -42,26 +40,20 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private final List<Suggestion> mSuggestions;
|
||||||
@Deprecated // in favor of mSuggestionsV2
|
|
||||||
private final List<Tile> mSuggestions;
|
|
||||||
private final List<Suggestion> mSuggestionsV2;
|
|
||||||
private final IconCache mCache;
|
private final IconCache mCache;
|
||||||
private final List<String> mSuggestionsShownLogged;
|
private final List<String> mSuggestionsShownLogged;
|
||||||
private final SuggestionControllerMixin mSuggestionControllerMixin;
|
private final SuggestionControllerMixin mSuggestionControllerMixin;
|
||||||
|
|
||||||
public SuggestionAdapter(Context context, SuggestionControllerMixin suggestionControllerMixin,
|
public SuggestionAdapter(Context context, SuggestionControllerMixin suggestionControllerMixin,
|
||||||
List<Tile> suggestions, List<Suggestion> suggestionsV2,
|
List<Suggestion> suggestions, List<String> suggestionsShownLogged) {
|
||||||
List<String> suggestionsShownLogged) {
|
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSuggestionControllerMixin = suggestionControllerMixin;
|
mSuggestionControllerMixin = suggestionControllerMixin;
|
||||||
mSuggestions = suggestions;
|
mSuggestions = suggestions;
|
||||||
mSuggestionsV2 = suggestionsV2;
|
|
||||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||||
mCache = new IconCache(context);
|
mCache = new IconCache(context);
|
||||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||||
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
|
||||||
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
|
|
||||||
|
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
}
|
}
|
||||||
@@ -74,15 +66,11 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||||
if (mSuggestions != null) {
|
bindSuggestion(holder, position);
|
||||||
bindSuggestionTile(holder, position);
|
|
||||||
} else {
|
|
||||||
bindSuggestion(holder, position);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindSuggestion(DashboardItemHolder holder, int position) {
|
private void bindSuggestion(DashboardItemHolder holder, int position) {
|
||||||
final Suggestion suggestion = mSuggestionsV2.get(position);
|
final Suggestion suggestion = mSuggestions.get(position);
|
||||||
final String id = suggestion.getId();
|
final String id = suggestion.getId();
|
||||||
if (!mSuggestionsShownLogged.contains(id)) {
|
if (!mSuggestionsShownLogged.contains(id)) {
|
||||||
mMetricsFeatureProvider.action(
|
mMetricsFeatureProvider.action(
|
||||||
@@ -101,7 +89,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
}
|
}
|
||||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||||
if (divider != null) {
|
if (divider != null) {
|
||||||
divider.setVisibility(position < mSuggestionsV2.size() - 1 ? View.VISIBLE : View.GONE);
|
divider.setVisibility(position < mSuggestions.size() - 1 ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
View clickHandler = holder.itemView;
|
View clickHandler = holder.itemView;
|
||||||
// If a view with @android:id/primary is defined, use that as the click handler
|
// If a view with @android:id/primary is defined, use that as the click handler
|
||||||
@@ -121,110 +109,32 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor {@link #bindSuggestion(DashboardItemHolder, int)}.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private void bindSuggestionTile(DashboardItemHolder holder, int position) {
|
|
||||||
final Tile suggestion = (Tile) mSuggestions.get(position);
|
|
||||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
|
||||||
mContext, suggestion);
|
|
||||||
// This is for cases when a suggestion is dismissed and the next one comes to view
|
|
||||||
if (!mSuggestionsShownLogged.contains(suggestionId)) {
|
|
||||||
mMetricsFeatureProvider.action(
|
|
||||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, suggestionId,
|
|
||||||
mSuggestionFeatureProvider.getLoggingTaggedData(mContext));
|
|
||||||
mSuggestionsShownLogged.add(suggestionId);
|
|
||||||
}
|
|
||||||
if (suggestion.remoteViews != null) {
|
|
||||||
final ViewGroup itemView = (ViewGroup) holder.itemView;
|
|
||||||
itemView.removeAllViews();
|
|
||||||
itemView.addView(suggestion.remoteViews.apply(itemView.getContext(), itemView));
|
|
||||||
} else {
|
|
||||||
holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
|
|
||||||
holder.title.setText(suggestion.title);
|
|
||||||
if (!TextUtils.isEmpty(suggestion.summary)) {
|
|
||||||
holder.summary.setText(suggestion.summary);
|
|
||||||
holder.summary.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
holder.summary.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
|
||||||
if (divider != null) {
|
|
||||||
divider.setVisibility(position < mSuggestions.size() - 1 ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
View clickHandler = holder.itemView;
|
|
||||||
// If a view with @android:id/primary is defined, use that as the click handler
|
|
||||||
// instead.
|
|
||||||
final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
|
|
||||||
if (primaryAction != null) {
|
|
||||||
clickHandler = primaryAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
clickHandler.setOnClickListener(v -> {
|
|
||||||
mMetricsFeatureProvider.action(mContext,
|
|
||||||
MetricsEvent.ACTION_SETTINGS_SUGGESTION, suggestionId,
|
|
||||||
mSuggestionFeatureProvider.getLoggingTaggedData(mContext));
|
|
||||||
((SettingsActivity) mContext).startSuggestion(suggestion.intent);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long getItemId(int position) {
|
public long getItemId(int position) {
|
||||||
if (mSuggestions != null) {
|
return Objects.hash(mSuggestions.get(position).getId());
|
||||||
return Objects.hash(mSuggestions.get(position).title);
|
|
||||||
} else {
|
|
||||||
return Objects.hash(mSuggestionsV2.get(position).getId());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (mSuggestions != null) {
|
final Suggestion suggestion = getSuggestion(position);
|
||||||
Tile suggestion = getSuggestion(position);
|
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
||||||
|
return R.layout.suggestion_tile_with_button;
|
||||||
return suggestion.remoteViews != null
|
|
||||||
? R.layout.suggestion_tile_remote_container
|
|
||||||
: R.layout.suggestion_tile;
|
|
||||||
} else {
|
} else {
|
||||||
final Suggestion suggestion = getSuggestionsV2(position);
|
return R.layout.suggestion_tile;
|
||||||
if ((suggestion.getFlags() & Suggestion.FLAG_HAS_BUTTON) != 0) {
|
|
||||||
return R.layout.suggestion_tile_with_button;
|
|
||||||
} else {
|
|
||||||
return R.layout.suggestion_tile;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mSuggestions != null) {
|
return mSuggestions.size();
|
||||||
return mSuggestions.size();
|
|
||||||
} else {
|
|
||||||
return mSuggestionsV2.size();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tile getSuggestion(int position) {
|
public Suggestion getSuggestion(int position) {
|
||||||
final long itemId = getItemId(position);
|
final long itemId = getItemId(position);
|
||||||
if (mSuggestions == null) {
|
if (mSuggestions == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Tile tile : mSuggestions) {
|
for (Suggestion suggestion : mSuggestions) {
|
||||||
if (Objects.hash(tile.title) == itemId) {
|
|
||||||
return tile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Suggestion getSuggestionsV2(int position) {
|
|
||||||
final long itemId = getItemId(position);
|
|
||||||
if (mSuggestionsV2 == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
for (Suggestion suggestion : mSuggestionsV2) {
|
|
||||||
if (Objects.hash(suggestion.getId()) == itemId) {
|
if (Objects.hash(suggestion.getId()) == itemId) {
|
||||||
return suggestion;
|
return suggestion;
|
||||||
}
|
}
|
||||||
@@ -232,13 +142,8 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSuggestion(Tile suggestion) {
|
public void removeSuggestion(Suggestion suggestion) {
|
||||||
mSuggestions.remove(suggestion);
|
mSuggestions.remove(suggestion);
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSuggestion(Suggestion suggestion) {
|
|
||||||
mSuggestionsV2.remove(suggestion);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,27 +23,10 @@ import android.support.v7.widget.helper.ItemTouchHelper;
|
|||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback {
|
public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback {
|
||||||
|
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #getSuggestionAt(int)}
|
|
||||||
* Returns suggestion tile data from the callback
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
Tile getSuggestionForPosition(int position);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}
|
|
||||||
* Called when a suggestion is dismissed.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void onSuggestionDismissed(Tile suggestion);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns suggestion tile data from the callback
|
* Returns suggestion tile data from the callback
|
||||||
*/
|
*/
|
||||||
@@ -58,20 +41,13 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||||
private final SuggestionControllerMixin mSuggestionMixin;
|
private final SuggestionControllerMixin mSuggestionMixin;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of the new Suggestion backend.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private final SuggestionParser mSuggestionParser;
|
|
||||||
private final Callback mCallback;
|
private final Callback mCallback;
|
||||||
|
|
||||||
public SuggestionDismissController(Context context, RecyclerView recyclerView,
|
public SuggestionDismissController(Context context, RecyclerView recyclerView,
|
||||||
SuggestionControllerMixin suggestionMixin, SuggestionParser parser, Callback callback) {
|
SuggestionControllerMixin suggestionMixin, Callback callback) {
|
||||||
super(0, ItemTouchHelper.START | ItemTouchHelper.END);
|
super(0, ItemTouchHelper.START | ItemTouchHelper.END);
|
||||||
mSuggestionMixin = suggestionMixin;
|
mSuggestionMixin = suggestionMixin;
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mSuggestionParser = parser;
|
|
||||||
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
|
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
.getSuggestionFeatureProvider(context);
|
.getSuggestionFeatureProvider(context);
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
@@ -103,13 +79,7 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
|||||||
}
|
}
|
||||||
final int position = viewHolder.getAdapterPosition();
|
final int position = viewHolder.getAdapterPosition();
|
||||||
final Suggestion suggestionV2 = mCallback.getSuggestionAt(position);
|
final Suggestion suggestionV2 = mCallback.getSuggestionAt(position);
|
||||||
if (suggestionV2 != null) {
|
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionMixin, suggestionV2);
|
||||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionMixin, suggestionV2);
|
mCallback.onSuggestionDismissed(suggestionV2);
|
||||||
mCallback.onSuggestionDismissed(suggestionV2);
|
|
||||||
} else {
|
|
||||||
final Tile suggestion = mCallback.getSuggestionForPosition(position);
|
|
||||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionParser, suggestion);
|
|
||||||
mCallback.onSuggestionDismissed(suggestion);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import android.support.annotation.NonNull;
|
|||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -33,14 +32,6 @@ public interface SuggestionFeatureProvider {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not the whole suggestion feature is enabled.
|
* Whether or not the whole suggestion feature is enabled.
|
||||||
*
|
|
||||||
* @deprecated in favor of {@link #isSuggestionV2Enabled(Context)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
boolean isSuggestionEnabled(Context context);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether or not the suggestion v2 feature is enabled.
|
|
||||||
*/
|
*/
|
||||||
boolean isSuggestionV2Enabled(Context context);
|
boolean isSuggestionV2Enabled(Context context);
|
||||||
|
|
||||||
@@ -62,44 +53,17 @@ public interface SuggestionFeatureProvider {
|
|||||||
*/
|
*/
|
||||||
SharedPreferences getSharedPrefs(Context context);
|
SharedPreferences getSharedPrefs(Context context);
|
||||||
|
|
||||||
/**
|
|
||||||
* Ranks the list of suggestions in place.
|
|
||||||
*
|
|
||||||
* @param suggestions List of suggestion Tiles
|
|
||||||
* @param suggestionIds List of suggestion ids corresponding to the suggestion tiles.
|
|
||||||
* @deprecated in favor of SettingsIntelligence
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Only keep top few suggestions from exclusive suggestions.
|
* Only keep top few suggestions from exclusive suggestions.
|
||||||
*/
|
*/
|
||||||
void filterExclusiveSuggestions(List<Tile> suggestions);
|
void filterExclusiveSuggestions(List<Tile> suggestions);
|
||||||
|
|
||||||
/**
|
|
||||||
* Dismisses a suggestion.
|
|
||||||
*
|
|
||||||
* @deprecated in favor of {@link #dismissSuggestion(Context, SuggestionControllerMixin,
|
|
||||||
* Suggestion)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dismisses a suggestion.
|
* Dismisses a suggestion.
|
||||||
*/
|
*/
|
||||||
void dismissSuggestion(Context context, SuggestionControllerMixin suggestionMixin,
|
void dismissSuggestion(Context context, SuggestionControllerMixin suggestionMixin,
|
||||||
Suggestion suggestion);
|
Suggestion suggestion);
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns an identifier for the suggestion
|
|
||||||
*
|
|
||||||
* @deprecated in favor or {@link Suggestion#getId()}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
String getSuggestionIdentifier(Context context, Tile suggestion);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns common tagged data for suggestion logging.
|
* Returns common tagged data for suggestion logging.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,19 +16,15 @@
|
|||||||
|
|
||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import static com.android.settings.core.FeatureFlags.SUGGESTIONS_V2;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
@@ -54,7 +50,6 @@ import com.android.settings.support.NewDeviceIntroSuggestionActivity;
|
|||||||
import com.android.settings.wallpaper.WallpaperSuggestionActivity;
|
import com.android.settings.wallpaper.WallpaperSuggestionActivity;
|
||||||
import com.android.settings.wifi.WifiCallingSuggestionActivity;
|
import com.android.settings.wifi.WifiCallingSuggestionActivity;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -65,23 +60,13 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
|
|
||||||
private static final String SHARED_PREF_FILENAME = "suggestions";
|
private static final String SHARED_PREF_FILENAME = "suggestions";
|
||||||
|
|
||||||
private final SuggestionRanker mSuggestionRanker;
|
|
||||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSuggestionEnabled(Context context) {
|
|
||||||
final ActivityManager am =
|
|
||||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
boolean isLowRamDevice = am.isLowRamDevice();
|
|
||||||
return !isLowRamDevice && !isV2Enabled(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSuggestionV2Enabled(Context context) {
|
public boolean isSuggestionV2Enabled(Context context) {
|
||||||
final ActivityManager am =
|
final ActivityManager am =
|
||||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
boolean isLowRamDevice = am.isLowRamDevice();
|
return !am.isLowRamDevice();
|
||||||
return !isLowRamDevice && isV2Enabled(context);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -91,10 +76,6 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
"com.android.settings.intelligence.suggestions.SuggestionService");
|
"com.android.settings.intelligence.suggestions.SuggestionService");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isV2Enabled(Context context) {
|
|
||||||
return FeatureFlagUtils.isEnabled(context, SUGGESTIONS_V2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSmartSuggestionEnabled(Context context) {
|
public boolean isSmartSuggestionEnabled(Context context) {
|
||||||
return false;
|
return false;
|
||||||
@@ -143,17 +124,10 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
|
|
||||||
public SuggestionFeatureProviderImpl(Context context) {
|
public SuggestionFeatureProviderImpl(Context context) {
|
||||||
final Context appContext = context.getApplicationContext();
|
final Context appContext = context.getApplicationContext();
|
||||||
mSuggestionRanker = new SuggestionRanker(
|
|
||||||
new SuggestionFeaturizer(new EventStore(appContext)));
|
|
||||||
mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
|
mMetricsFeatureProvider = FeatureFactory.getFactory(appContext)
|
||||||
.getMetricsFeatureProvider();
|
.getMetricsFeatureProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds) {
|
|
||||||
mSuggestionRanker.rankSuggestions(suggestions, suggestionIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filterExclusiveSuggestions(List<Tile> suggestions) {
|
public void filterExclusiveSuggestions(List<Tile> suggestions) {
|
||||||
if (suggestions == null) {
|
if (suggestions == null) {
|
||||||
@@ -165,26 +139,6 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion) {
|
|
||||||
if (parser == null || suggestion == null || context == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Pair<Integer, Object>[] taggedData = getLoggingTaggedData(context);
|
|
||||||
|
|
||||||
mMetricsFeatureProvider.action(
|
|
||||||
context, MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
|
||||||
getSuggestionIdentifier(context, suggestion),
|
|
||||||
taggedData);
|
|
||||||
if (!parser.dismissSuggestion(suggestion)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
context.getPackageManager().setComponentEnabledSetting(
|
|
||||||
suggestion.intent.getComponent(),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
||||||
PackageManager.DONT_KILL_APP);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dismissSuggestion(Context context, SuggestionControllerMixin mixin,
|
public void dismissSuggestion(Context context, SuggestionControllerMixin mixin,
|
||||||
Suggestion suggestion) {
|
Suggestion suggestion) {
|
||||||
@@ -197,25 +151,10 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
|||||||
mixin.dismissSuggestion(suggestion);
|
mixin.dismissSuggestion(suggestion);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
|
||||||
if (suggestion.intent == null || suggestion.intent.getComponent() == null
|
|
||||||
|| context == null) {
|
|
||||||
return "unknown_suggestion";
|
|
||||||
}
|
|
||||||
String packageName = suggestion.intent.getComponent().getPackageName();
|
|
||||||
if (packageName.equals(context.getPackageName())) {
|
|
||||||
// Since Settings provides several suggestions, fill in the class instead of the
|
|
||||||
// package for these.
|
|
||||||
packageName = suggestion.intent.getComponent().getClassName();
|
|
||||||
}
|
|
||||||
return packageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Pair<Integer, Object>[] getLoggingTaggedData(Context context) {
|
public Pair<Integer, Object>[] getLoggingTaggedData(Context context) {
|
||||||
final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
final boolean isSmartSuggestionEnabled = isSmartSuggestionEnabled(context);
|
||||||
return new Pair[]{Pair.create(
|
return new Pair[] {Pair.create(
|
||||||
MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED,
|
MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED,
|
||||||
isSmartSuggestionEnabled ? 1 : 0)};
|
isSmartSuggestionEnabled ? 1 : 0)};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a set of interaction features (i.e., metrics) to represent each setting suggestion. These
|
|
||||||
* features currently include normalized time from previous events (shown, dismissed and clicked)
|
|
||||||
* for any particular suggestion and also counts of these events. These features are used as signals
|
|
||||||
* to find the best ranking for suggestion items.
|
|
||||||
*/
|
|
||||||
public class SuggestionFeaturizer {
|
|
||||||
|
|
||||||
// Key of the features used for ranking.
|
|
||||||
public static final String FEATURE_IS_SHOWN = "is_shown";
|
|
||||||
public static final String FEATURE_IS_DISMISSED = "is_dismissed";
|
|
||||||
public static final String FEATURE_IS_CLICKED = "is_clicked";
|
|
||||||
public static final String FEATURE_TIME_FROM_LAST_SHOWN = "time_from_last_shown";
|
|
||||||
public static final String FEATURE_TIME_FROM_LAST_DISMISSED = "time_from_last_dismissed";
|
|
||||||
public static final String FEATURE_TIME_FROM_LAST_CLICKED = "time_from_last_clicked";
|
|
||||||
public static final String FEATURE_SHOWN_COUNT = "shown_count";
|
|
||||||
public static final String FEATURE_DISMISSED_COUNT = "dismissed_count";
|
|
||||||
public static final String FEATURE_CLICKED_COUNT = "clicked_count";
|
|
||||||
|
|
||||||
// The following numbers are estimated from histograms.
|
|
||||||
public static final double TIME_NORMALIZATION_FACTOR = 2e10;
|
|
||||||
public static final double COUNT_NORMALIZATION_FACTOR = 500;
|
|
||||||
|
|
||||||
private final EventStore mEventStore;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param eventStore An instance of {@code EventStore} which maintains the recorded suggestion
|
|
||||||
* events.
|
|
||||||
*/
|
|
||||||
public SuggestionFeaturizer(EventStore eventStore) {
|
|
||||||
mEventStore = eventStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts the features for each package name.
|
|
||||||
*
|
|
||||||
* @param pkgNames: List of package names for which features are queried.
|
|
||||||
* @return A Map containing the features, keyed by the package names. Each map value contains
|
|
||||||
* another map with key-value pairs of the features.
|
|
||||||
*/
|
|
||||||
public Map<String, Map<String, Double>> featurize(List<String> pkgNames) {
|
|
||||||
Map<String, Map<String, Double>> features = new HashMap<>();
|
|
||||||
Long curTimeMs = System.currentTimeMillis();
|
|
||||||
for (String pkgName : pkgNames) {
|
|
||||||
Map<String, Double> featureMap = new HashMap<>();
|
|
||||||
features.put(pkgName, featureMap);
|
|
||||||
Long lastShownTime = mEventStore
|
|
||||||
.readMetric(pkgName, EventStore.EVENT_SHOWN, EventStore.METRIC_LAST_EVENT_TIME);
|
|
||||||
Long lastDismissedTime = mEventStore.readMetric(pkgName, EventStore.EVENT_DISMISSED,
|
|
||||||
EventStore.METRIC_LAST_EVENT_TIME);
|
|
||||||
Long lastClickedTime = mEventStore.readMetric(pkgName, EventStore.EVENT_CLICKED,
|
|
||||||
EventStore.METRIC_LAST_EVENT_TIME);
|
|
||||||
featureMap.put(FEATURE_IS_SHOWN, booleanToDouble(lastShownTime > 0));
|
|
||||||
featureMap.put(FEATURE_IS_DISMISSED, booleanToDouble(lastDismissedTime > 0));
|
|
||||||
featureMap.put(FEATURE_IS_CLICKED, booleanToDouble(lastClickedTime > 0));
|
|
||||||
featureMap.put(FEATURE_TIME_FROM_LAST_SHOWN,
|
|
||||||
normalizedTimeDiff(curTimeMs, lastShownTime));
|
|
||||||
featureMap.put(FEATURE_TIME_FROM_LAST_DISMISSED,
|
|
||||||
normalizedTimeDiff(curTimeMs, lastDismissedTime));
|
|
||||||
featureMap.put(FEATURE_TIME_FROM_LAST_CLICKED,
|
|
||||||
normalizedTimeDiff(curTimeMs, lastClickedTime));
|
|
||||||
featureMap.put(FEATURE_SHOWN_COUNT, normalizedCount(mEventStore
|
|
||||||
.readMetric(pkgName, EventStore.EVENT_SHOWN, EventStore.METRIC_COUNT)));
|
|
||||||
featureMap.put(FEATURE_DISMISSED_COUNT, normalizedCount(mEventStore
|
|
||||||
.readMetric(pkgName, EventStore.EVENT_DISMISSED, EventStore.METRIC_COUNT)));
|
|
||||||
featureMap.put(FEATURE_CLICKED_COUNT, normalizedCount(mEventStore
|
|
||||||
.readMetric(pkgName, EventStore.EVENT_CLICKED, EventStore.METRIC_COUNT)));
|
|
||||||
}
|
|
||||||
return features;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double booleanToDouble(boolean bool) {
|
|
||||||
return bool ? 1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double normalizedTimeDiff(long curTimeMs, long preTimeMs) {
|
|
||||||
return Math.min(1, (curTimeMs - preTimeMs) / TIME_NORMALIZATION_FACTOR);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static double normalizedCount(long count) {
|
|
||||||
return Math.min(1, count / COUNT_NORMALIZATION_FACTOR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class SuggestionRanker {
|
|
||||||
|
|
||||||
private static final String TAG = "SuggestionRanker";
|
|
||||||
|
|
||||||
// The following coefficients form a linear model, which mixes the features to obtain a
|
|
||||||
// relevance metric for ranking the suggestion items. This model is learned with off-line data
|
|
||||||
// by training a binary classifier to detect the clicked items. The higher the obtained
|
|
||||||
// relevance metric, the higher chance of getting clicked.
|
|
||||||
private static final Map<String, Double> WEIGHTS = new HashMap<String, Double>() {{
|
|
||||||
put(SuggestionFeaturizer.FEATURE_IS_SHOWN, 5.05140842519);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_IS_DISMISSED, 2.29641455171);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_IS_CLICKED, -2.98812233623);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_SHOWN, 5.02807250202);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_DISMISSED, 2.49589700842);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_CLICKED, -4.3377039948);
|
|
||||||
put(SuggestionFeaturizer.FEATURE_SHOWN_COUNT, -2.35993512546);
|
|
||||||
}};
|
|
||||||
|
|
||||||
private final SuggestionFeaturizer mSuggestionFeaturizer;
|
|
||||||
|
|
||||||
private final Map<Tile, Double> relevanceMetrics;
|
|
||||||
|
|
||||||
Comparator<Tile> suggestionComparator = new Comparator<Tile>() {
|
|
||||||
@Override
|
|
||||||
public int compare(Tile suggestion1, Tile suggestion2) {
|
|
||||||
return relevanceMetrics.get(suggestion1) < relevanceMetrics.get(suggestion2) ? 1 : -1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public SuggestionRanker(SuggestionFeaturizer suggestionFeaturizer) {
|
|
||||||
mSuggestionFeaturizer = suggestionFeaturizer;
|
|
||||||
relevanceMetrics = new HashMap<Tile, Double>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds) {
|
|
||||||
relevanceMetrics.clear();
|
|
||||||
Map<String, Map<String, Double>> features = mSuggestionFeaturizer.featurize(suggestionIds);
|
|
||||||
for (int i = 0; i < suggestionIds.size(); i++) {
|
|
||||||
relevanceMetrics.put(suggestions.get(i),
|
|
||||||
getRelevanceMetric(features.get(suggestionIds.get(i))));
|
|
||||||
}
|
|
||||||
Collections.sort(suggestions, suggestionComparator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
double getRelevanceMetric(Map<String, Double> features) {
|
|
||||||
double sum = 0;
|
|
||||||
if (features == null) {
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
for (String feature : WEIGHTS.keySet()) {
|
|
||||||
sum += WEIGHTS.get(feature) * features.get(feature);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -135,7 +135,6 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
return new ArrayList<>(mControllers);
|
return new ArrayList<>(mControllers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void populateList() {
|
private void populateList() {
|
||||||
if (!mDynamicPreferences.isEmpty()) {
|
if (!mDynamicPreferences.isEmpty()) {
|
||||||
// If there's anything in mChannelGroups, we've called populateChannelList twice.
|
// If there's anything in mChannelGroups, we've called populateChannelList twice.
|
||||||
@@ -164,61 +163,41 @@ public class AppNotificationSettings extends NotificationSettingsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void populateGroupList() {
|
private void populateGroupList() {
|
||||||
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
|
||||||
groupCategory.setTitle(R.string.notification_channels);
|
|
||||||
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
|
||||||
groupCategory.setOrderingAsAdded(true);
|
|
||||||
getPreferenceScreen().addPreference(groupCategory);
|
|
||||||
mDynamicPreferences.add(groupCategory);
|
|
||||||
for (NotificationChannelGroup group : mChannelGroupList) {
|
for (NotificationChannelGroup group : mChannelGroupList) {
|
||||||
final List<NotificationChannel> channels = group.getChannels();
|
PreferenceCategory groupCategory = new PreferenceCategory(getPrefContext());
|
||||||
int N = channels.size();
|
groupCategory.setOrderingAsAdded(true);
|
||||||
// app defined groups with one channel and channels with no group display the channel
|
getPreferenceScreen().addPreference(groupCategory);
|
||||||
// name and no summary and link directly to the channel page unless the group is blocked
|
mDynamicPreferences.add(groupCategory);
|
||||||
if ((group.getId() == null || N < 2) && !group.isBlocked()) {
|
if (group.getId() == null) {
|
||||||
Collections.sort(channels, mChannelComparator);
|
groupCategory.setTitle(mChannelGroupList.size() > 1
|
||||||
for (int i = 0; i < N; i++) {
|
? R.string.notification_channels_other
|
||||||
final NotificationChannel channel = channels.get(i);
|
: R.string.notification_channels);
|
||||||
populateSingleChannelPrefs(groupCategory, channel, "");
|
groupCategory.setKey(KEY_GENERAL_CATEGORY);
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
populateGroupPreference(groupCategory, group, N);
|
groupCategory.setTitle(group.getName());
|
||||||
|
groupCategory.setKey(group.getId());
|
||||||
|
Bundle groupArgs = new Bundle();
|
||||||
|
groupArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
||||||
|
groupArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
|
||||||
|
groupArgs.putString(Settings.EXTRA_CHANNEL_GROUP_ID, group.getId());
|
||||||
|
Intent channelIntent = Utils.onBuildStartFragmentIntent(getActivity(),
|
||||||
|
ChannelGroupNotificationSettings.class.getName(),
|
||||||
|
groupArgs, null, R.string.notification_group_title,
|
||||||
|
null, false, getMetricsCategory());
|
||||||
|
groupCategory.setIntent(channelIntent);
|
||||||
|
populateGroupToggle(groupCategory, group);
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<NotificationChannel> channels = group.getChannels();
|
||||||
|
Collections.sort(channels, mChannelComparator);
|
||||||
|
int N = channels.size();
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
final NotificationChannel channel = channels.get(i);
|
||||||
|
populateSingleChannelPrefs(groupCategory, channel, group.isBlocked());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void populateGroupPreference(PreferenceGroup parent,
|
|
||||||
final NotificationChannelGroup group, int channelCount) {
|
|
||||||
MasterSwitchPreference groupPref = new MasterSwitchPreference(
|
|
||||||
getPrefContext());
|
|
||||||
groupPref.setSwitchEnabled(mSuspendedAppsAdmin == null
|
|
||||||
&& isChannelGroupBlockable(group));
|
|
||||||
groupPref.setKey(group.getId());
|
|
||||||
groupPref.setTitle(group.getName());
|
|
||||||
groupPref.setChecked(!group.isBlocked());
|
|
||||||
groupPref.setSummary(getResources().getQuantityString(
|
|
||||||
R.plurals.notification_group_summary, channelCount, channelCount));
|
|
||||||
Bundle groupArgs = new Bundle();
|
|
||||||
groupArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
|
||||||
groupArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
|
|
||||||
groupArgs.putString(Settings.EXTRA_CHANNEL_GROUP_ID, group.getId());
|
|
||||||
Intent groupIntent = Utils.onBuildStartFragmentIntent(getActivity(),
|
|
||||||
ChannelGroupNotificationSettings.class.getName(),
|
|
||||||
groupArgs, null, R.string.notification_group_title, null, false,
|
|
||||||
getMetricsCategory());
|
|
||||||
groupPref.setIntent(groupIntent);
|
|
||||||
|
|
||||||
groupPref.setOnPreferenceChangeListener(
|
|
||||||
(preference, o) -> {
|
|
||||||
boolean value = (Boolean) o;
|
|
||||||
group.setBlocked(!value);
|
|
||||||
mBackend.updateChannelGroup(mPkg, mUid, group);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
parent.addPreference(groupPref);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
|
private Comparator<NotificationChannelGroup> mChannelGroupComparator =
|
||||||
new Comparator<NotificationChannelGroup>() {
|
new Comparator<NotificationChannelGroup>() {
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,8 @@ public class BlockPreferenceController extends NotificationPreferenceController
|
|||||||
LayoutPreference pref = (LayoutPreference) preference;
|
LayoutPreference pref = (LayoutPreference) preference;
|
||||||
SwitchBar bar = pref.findViewById(R.id.switch_bar);
|
SwitchBar bar = pref.findViewById(R.id.switch_bar);
|
||||||
if (bar != null) {
|
if (bar != null) {
|
||||||
|
bar.setSwitchBarText(R.string.notification_switch_label,
|
||||||
|
R.string.notification_switch_label);
|
||||||
bar.show();
|
bar.show();
|
||||||
try {
|
try {
|
||||||
bar.addOnSwitchChangeListener(this);
|
bar.addOnSwitchChangeListener(this);
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package com.android.settings.notification;
|
|||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -98,9 +97,7 @@ public class ChannelGroupNotificationSettings extends NotificationSettingsBase {
|
|||||||
Collections.sort(channels, mChannelComparator);
|
Collections.sort(channels, mChannelComparator);
|
||||||
for (NotificationChannel channel : channels) {
|
for (NotificationChannel channel : channels) {
|
||||||
mDynamicPreferences.add(populateSingleChannelPrefs(
|
mDynamicPreferences.add(populateSingleChannelPrefs(
|
||||||
getPreferenceScreen(), channel,
|
getPreferenceScreen(), channel, mChannelGroup.isBlocked()));
|
||||||
ImportancePreferenceController.getImportanceSummary(
|
|
||||||
getPrefContext(), channel)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
if (preference.isEnabled()) {
|
if (preference.isEnabled()) {
|
||||||
Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
|
Intent channelIntent = Utils.onBuildStartFragmentIntent(mContext,
|
||||||
ChannelImportanceSettings.class.getName(),
|
ChannelImportanceSettings.class.getName(),
|
||||||
channelArgs, null, R.string.notification_importance_title, null,
|
channelArgs, null,
|
||||||
|
R.string.notification_importance_title, null,
|
||||||
false, getMetricsCategory());
|
false, getMetricsCategory());
|
||||||
preference.setIntent(channelIntent);
|
preference.setIntent(channelIntent);
|
||||||
preference.setSummary(getImportanceSummary(mContext, mChannel));
|
preference.setSummary(getImportanceSummary(mContext, mChannel));
|
||||||
@@ -82,23 +83,19 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected static String getImportanceSummary(Context context, NotificationChannel channel) {
|
protected static String getImportanceSummary(Context context, NotificationChannel channel) {
|
||||||
String title;
|
String summary = "";
|
||||||
String summary = null;
|
|
||||||
int importance = channel.getImportance();
|
int importance = channel.getImportance();
|
||||||
switch (importance) {
|
switch (importance) {
|
||||||
case IMPORTANCE_UNSPECIFIED:
|
case IMPORTANCE_UNSPECIFIED:
|
||||||
title = context.getString(R.string.notification_importance_unspecified);
|
summary = context.getString(R.string.notification_importance_unspecified);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_MIN:
|
case NotificationManager.IMPORTANCE_MIN:
|
||||||
title = context.getString(R.string.notification_importance_min_title);
|
|
||||||
summary = context.getString(R.string.notification_importance_min);
|
summary = context.getString(R.string.notification_importance_min);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_LOW:
|
case NotificationManager.IMPORTANCE_LOW:
|
||||||
title = context.getString(R.string.notification_importance_low_title);
|
|
||||||
summary = context.getString(R.string.notification_importance_low);
|
summary = context.getString(R.string.notification_importance_low);
|
||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_DEFAULT:
|
case NotificationManager.IMPORTANCE_DEFAULT:
|
||||||
title = context.getString(R.string.notification_importance_default_title);
|
|
||||||
if (SoundPreferenceController.hasValidSound(channel)) {
|
if (SoundPreferenceController.hasValidSound(channel)) {
|
||||||
summary = context.getString(R.string.notification_importance_default);
|
summary = context.getString(R.string.notification_importance_default);
|
||||||
} else {
|
} else {
|
||||||
@@ -107,7 +104,6 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
break;
|
break;
|
||||||
case NotificationManager.IMPORTANCE_HIGH:
|
case NotificationManager.IMPORTANCE_HIGH:
|
||||||
case NotificationManager.IMPORTANCE_MAX:
|
case NotificationManager.IMPORTANCE_MAX:
|
||||||
title = context.getString(R.string.notification_importance_high_title);
|
|
||||||
if (SoundPreferenceController.hasValidSound(channel)) {
|
if (SoundPreferenceController.hasValidSound(channel)) {
|
||||||
summary = context.getString(R.string.notification_importance_high);
|
summary = context.getString(R.string.notification_importance_high);
|
||||||
} else {
|
} else {
|
||||||
@@ -118,10 +114,6 @@ public class ImportancePreferenceController extends NotificationPreferenceContro
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (summary != null) {
|
return summary;
|
||||||
return context.getString(R.string.notification_importance_divider, title, summary);
|
|
||||||
} else {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ import android.os.UserManager;
|
|||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.service.notification.NotificationListenerService;
|
import android.service.notification.NotificationListenerService;
|
||||||
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
@@ -214,7 +215,6 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
for (ResolveInfo ri : resolveInfos) {
|
for (ResolveInfo ri : resolveInfos) {
|
||||||
final ActivityInfo activityInfo = ri.activityInfo;
|
final ActivityInfo activityInfo = ri.activityInfo;
|
||||||
final ApplicationInfo appInfo = activityInfo.applicationInfo;
|
|
||||||
if (mAppRow.settingsIntent != null) {
|
if (mAppRow.settingsIntent != null) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Log.d(TAG, "Ignoring duplicate notification preference activity ("
|
Log.d(TAG, "Ignoring duplicate notification preference activity ("
|
||||||
@@ -225,7 +225,8 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
}
|
}
|
||||||
mAppRow.settingsIntent = intent
|
mAppRow.settingsIntent = intent
|
||||||
.setPackage(null)
|
.setPackage(null)
|
||||||
.setClassName(activityInfo.packageName, activityInfo.name);
|
.setClassName(activityInfo.packageName, activityInfo.name)
|
||||||
|
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
if (mChannel != null) {
|
if (mChannel != null) {
|
||||||
mAppRow.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
|
mAppRow.settingsIntent.putExtra(Notification.EXTRA_CHANNEL_ID, mChannel.getId());
|
||||||
}
|
}
|
||||||
@@ -257,17 +258,41 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void populateGroupToggle(final PreferenceGroup parent,
|
||||||
|
NotificationChannelGroup group) {
|
||||||
|
RestrictedSwitchPreference preference = new RestrictedSwitchPreference(getPrefContext());
|
||||||
|
preference.setTitle(R.string.notification_switch_label);
|
||||||
|
preference.setEnabled(mSuspendedAppsAdmin == null
|
||||||
|
&& isChannelGroupBlockable(group));
|
||||||
|
preference.setChecked(!group.isBlocked());
|
||||||
|
preference.setOnPreferenceClickListener(preference1 -> {
|
||||||
|
final boolean allowGroup = ((SwitchPreference) preference1).isChecked();
|
||||||
|
group.setBlocked(!allowGroup);
|
||||||
|
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, group);
|
||||||
|
|
||||||
|
for (int i = 0; i < parent.getPreferenceCount(); i++) {
|
||||||
|
Preference pref = parent.getPreference(i);
|
||||||
|
if (pref instanceof MasterSwitchPreference) {
|
||||||
|
((MasterSwitchPreference) pref).setSwitchEnabled(allowGroup);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
parent.addPreference(preference);
|
||||||
|
}
|
||||||
|
|
||||||
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
||||||
final NotificationChannel channel, String summary) {
|
final NotificationChannel channel, final boolean groupBlocked) {
|
||||||
MasterSwitchPreference channelPref = new MasterSwitchPreference(
|
MasterSwitchPreference channelPref = new MasterSwitchPreference(
|
||||||
getPrefContext());
|
getPrefContext());
|
||||||
channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
|
channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
|
||||||
&& isChannelBlockable(channel)
|
&& isChannelBlockable(channel)
|
||||||
&& isChannelConfigurable(channel));
|
&& isChannelConfigurable(channel)
|
||||||
|
&& !groupBlocked);
|
||||||
channelPref.setKey(channel.getId());
|
channelPref.setKey(channel.getId());
|
||||||
channelPref.setTitle(channel.getName());
|
channelPref.setTitle(channel.getName());
|
||||||
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
channelPref.setChecked(channel.getImportance() != IMPORTANCE_NONE);
|
||||||
channelPref.setSummary(summary);
|
|
||||||
Bundle channelArgs = new Bundle();
|
Bundle channelArgs = new Bundle();
|
||||||
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
channelArgs.putInt(AppInfoBase.ARG_PACKAGE_UID, mUid);
|
||||||
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
|
channelArgs.putString(AppInfoBase.ARG_PACKAGE_NAME, mPkg);
|
||||||
@@ -288,7 +313,6 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
channel.setImportance(importance);
|
channel.setImportance(importance);
|
||||||
channel.lockFields(
|
channel.lockFields(
|
||||||
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
NotificationChannel.USER_LOCKED_IMPORTANCE);
|
||||||
channelPref.setSummary(summary);
|
|
||||||
mBackend.updateChannel(mPkg, mUid, channel);
|
mBackend.updateChannel(mPkg, mUid, channel);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
public class ScreenPinningPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
|
||||||
|
|
||||||
|
public ScreenPinningPreferenceController(Context context) {
|
||||||
|
super(context, KEY_SCREEN_PINNING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (preference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (Settings.System.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
|
||||||
|
preference.setSummary(
|
||||||
|
mContext.getString(R.string.switch_on_text));
|
||||||
|
} else {
|
||||||
|
preference.setSummary(
|
||||||
|
mContext.getString(R.string.switch_off_text));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,6 +20,7 @@ import android.content.Context;
|
|||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.util.FeatureFlagUtils;
|
import android.util.FeatureFlagUtils;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.core.FeatureFlags;
|
import com.android.settings.core.FeatureFlags;
|
||||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -38,4 +39,9 @@ public interface SecurityFeatureProvider {
|
|||||||
|
|
||||||
/** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
|
/** Returns the {@link TrustAgentManager} bound to this {@link SecurityFeatureProvider}. */
|
||||||
TrustAgentManager getTrustAgentManager();
|
TrustAgentManager getTrustAgentManager();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@link LockPatternUtils} instance bound to application context.
|
||||||
|
*/
|
||||||
|
LockPatternUtils getLockPatternUtils(Context context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.text.TextUtils;
|
|||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -43,6 +44,7 @@ import java.util.TreeMap;
|
|||||||
public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
|
public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
|
||||||
|
|
||||||
private TrustAgentManager mTrustAgentManager;
|
private TrustAgentManager mTrustAgentManager;
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final Drawable DEFAULT_ICON = null;
|
static final Drawable DEFAULT_ICON = null;
|
||||||
@@ -195,4 +197,12 @@ public class SecurityFeatureProviderImpl implements SecurityFeatureProvider {
|
|||||||
}
|
}
|
||||||
return mTrustAgentManager;
|
return mTrustAgentManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public LockPatternUtils getLockPatternUtils(Context context) {
|
||||||
|
if (mLockPatternUtils == null) {
|
||||||
|
mLockPatternUtils = new LockPatternUtils(context.getApplicationContext());
|
||||||
|
}
|
||||||
|
return mLockPatternUtils;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,21 +7,15 @@ import android.content.Intent;
|
|||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.PersistableBundle;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.os.storage.StorageManager;
|
import android.os.storage.StorageManager;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.support.annotation.VisibleForTesting;
|
import android.support.annotation.VisibleForTesting;
|
||||||
import android.support.v14.preference.SwitchPreference;
|
import android.support.v14.preference.SwitchPreference;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.support.v7.preference.PreferenceGroup;
|
import android.support.v7.preference.PreferenceGroup;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.telephony.CarrierConfigManager;
|
|
||||||
import android.telephony.SubscriptionInfo;
|
|
||||||
import android.telephony.SubscriptionManager;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
@@ -43,6 +37,7 @@ import com.android.settings.password.ManagedLockPasswordProvider;
|
|||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.SearchIndexableRaw;
|
import com.android.settings.search.SearchIndexableRaw;
|
||||||
import com.android.settings.security.screenlock.ScreenLockSettings;
|
import com.android.settings.security.screenlock.ScreenLockSettings;
|
||||||
|
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
|
||||||
import com.android.settings.security.trustagent.TrustAgentManager;
|
import com.android.settings.security.trustagent.TrustAgentManager;
|
||||||
import com.android.settings.widget.GearPreference;
|
import com.android.settings.widget.GearPreference;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
import com.android.settingslib.RestrictedLockUtils;
|
||||||
@@ -67,13 +62,11 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
|
private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
|
||||||
private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
|
private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
|
||||||
private static final String KEY_SECURITY_CATEGORY = "security_category";
|
private static final String KEY_SECURITY_CATEGORY = "security_category";
|
||||||
@VisibleForTesting
|
|
||||||
static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
|
|
||||||
private static final String KEY_UNIFICATION = "unification";
|
private static final String KEY_UNIFICATION = "unification";
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
|
static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
|
||||||
private static final String KEY_ENCRYPTION_AND_CREDENTIALS = "encryption_and_credential";
|
private static final String KEY_ENCRYPTION_AND_CREDENTIALS = "encryption_and_credential";
|
||||||
private static final String KEY_LOCATION_SCANNING = "location_scanning";
|
private static final String KEY_LOCATION_SCANNING = "location_scanning";
|
||||||
private static final String KEY_LOCATION = "location";
|
private static final String KEY_LOCATION = "location";
|
||||||
|
|
||||||
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
|
||||||
@@ -85,10 +78,7 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
private static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
|
private static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
|
||||||
|
|
||||||
// Misc Settings
|
// Misc Settings
|
||||||
private static final String KEY_SIM_LOCK = "sim_lock_settings";
|
|
||||||
private static final String KEY_SHOW_PASSWORD = "show_password";
|
|
||||||
private static final String KEY_TRUST_AGENT = "trust_agent";
|
private static final String KEY_TRUST_AGENT = "trust_agent";
|
||||||
private static final String KEY_SCREEN_PINNING = "screen_pinning_settings";
|
|
||||||
|
|
||||||
// Security status
|
// Security status
|
||||||
private static final String KEY_SECURITY_STATUS = "security_status";
|
private static final String KEY_SECURITY_STATUS = "security_status";
|
||||||
@@ -100,7 +90,7 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
|
|
||||||
// These switch preferences need special handling since they're not all stored in Settings.
|
// These switch preferences need special handling since they're not all stored in Settings.
|
||||||
private static final String SWITCH_PREFERENCE_KEYS[] = {
|
private static final String SWITCH_PREFERENCE_KEYS[] = {
|
||||||
KEY_SHOW_PASSWORD, KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
|
KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int MY_USER_ID = UserHandle.myUserId();
|
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||||
@@ -109,7 +99,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
private DevicePolicyManager mDPM;
|
private DevicePolicyManager mDPM;
|
||||||
private SecurityFeatureProvider mSecurityFeatureProvider;
|
private SecurityFeatureProvider mSecurityFeatureProvider;
|
||||||
private TrustAgentManager mTrustAgentManager;
|
private TrustAgentManager mTrustAgentManager;
|
||||||
private SubscriptionManager mSubscriptionManager;
|
|
||||||
private UserManager mUm;
|
private UserManager mUm;
|
||||||
|
|
||||||
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
|
||||||
@@ -119,10 +108,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
private SwitchPreference mVisiblePatternProfile;
|
private SwitchPreference mVisiblePatternProfile;
|
||||||
private RestrictedSwitchPreference mUnifyProfile;
|
private RestrictedSwitchPreference mUnifyProfile;
|
||||||
|
|
||||||
private SwitchPreference mShowPassword;
|
|
||||||
|
|
||||||
private boolean mIsAdmin;
|
|
||||||
|
|
||||||
private Intent mTrustAgentClickIntent;
|
private Intent mTrustAgentClickIntent;
|
||||||
|
|
||||||
private int mProfileChallengeUserId;
|
private int mProfileChallengeUserId;
|
||||||
@@ -134,6 +119,10 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
|
private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
|
||||||
private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
|
private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
|
||||||
private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
|
private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
|
||||||
|
private ManageTrustAgentsPreferenceController mManageTrustAgentsPreferenceController;
|
||||||
|
private ScreenPinningPreferenceController mScreenPinningPreferenceController;
|
||||||
|
private SimLockPreferenceController mSimLockPreferenceController;
|
||||||
|
private ShowPasswordPreferenceController mShowPasswordPreferenceController;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
@@ -143,15 +132,15 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
|
mSecurityFeatureProvider = FeatureFactory.getFactory(context).getSecurityFeatureProvider();
|
||||||
mLocationController = new LocationPreferenceController(context, getLifecycle());
|
mLocationController = new LocationPreferenceController(context, getLifecycle());
|
||||||
mSubscriptionManager = SubscriptionManager.from(context);
|
mLockPatternUtils = mSecurityFeatureProvider.getLockPatternUtils(context);
|
||||||
mLockPatternUtils = new LockPatternUtils(context);
|
|
||||||
mManagedPasswordProvider = ManagedLockPasswordProvider.get(context, MY_USER_ID);
|
mManagedPasswordProvider = ManagedLockPasswordProvider.get(context, MY_USER_ID);
|
||||||
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
|
mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
|
||||||
mUm = UserManager.get(context);
|
mUm = UserManager.get(context);
|
||||||
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
mDashboardFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
.getDashboardFeatureProvider(context);
|
.getDashboardFeatureProvider(context);
|
||||||
mSecurityFeatureProvider = FeatureFactory.getFactory(context).getSecurityFeatureProvider();
|
|
||||||
mTrustAgentManager = mSecurityFeatureProvider.getTrustAgentManager();
|
mTrustAgentManager = mSecurityFeatureProvider.getTrustAgentManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,6 +162,10 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
= new EnterprisePrivacyPreferenceController(context);
|
= new EnterprisePrivacyPreferenceController(context);
|
||||||
mLockScreenNotificationPreferenceController
|
mLockScreenNotificationPreferenceController
|
||||||
= new LockScreenNotificationPreferenceController(context);
|
= new LockScreenNotificationPreferenceController(context);
|
||||||
|
mManageTrustAgentsPreferenceController = new ManageTrustAgentsPreferenceController(context);
|
||||||
|
mScreenPinningPreferenceController = new ScreenPinningPreferenceController(context);
|
||||||
|
mSimLockPreferenceController = new SimLockPreferenceController(context);
|
||||||
|
mShowPasswordPreferenceController = new ShowPasswordPreferenceController(context);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +175,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
|
|
||||||
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
|
||||||
|
|
||||||
|
|
||||||
if (savedInstanceState != null
|
if (savedInstanceState != null
|
||||||
&& savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
|
&& savedInstanceState.containsKey(TRUST_AGENT_CLICK_INTENT)) {
|
||||||
mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
|
mTrustAgentClickIntent = savedInstanceState.getParcelable(TRUST_AGENT_CLICK_INTENT);
|
||||||
@@ -280,15 +272,13 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
|
((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
mIsAdmin = mUm.isAdminUser();
|
|
||||||
|
|
||||||
// Fingerprint and trust agents
|
// Fingerprint and trust agents
|
||||||
int numberOfTrustAgent = 0;
|
|
||||||
PreferenceGroup securityCategory = (PreferenceGroup)
|
PreferenceGroup securityCategory = (PreferenceGroup)
|
||||||
root.findPreference(KEY_SECURITY_CATEGORY);
|
root.findPreference(KEY_SECURITY_CATEGORY);
|
||||||
if (securityCategory != null) {
|
if (securityCategory != null) {
|
||||||
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
|
maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
|
||||||
numberOfTrustAgent = addTrustAgentSettings(securityCategory);
|
addTrustAgentSettings(securityCategory);
|
||||||
setLockscreenPreferencesSummary(securityCategory);
|
setLockscreenPreferencesSummary(securityCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,24 +286,8 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
(SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
|
(SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
|
||||||
mUnifyProfile = (RestrictedSwitchPreference) root.findPreference(KEY_UNIFICATION);
|
mUnifyProfile = (RestrictedSwitchPreference) root.findPreference(KEY_UNIFICATION);
|
||||||
|
|
||||||
|
mSimLockPreferenceController.displayPreference(root);
|
||||||
// Do not display SIM lock for devices without an Icc card
|
mScreenPinningPreferenceController.displayPreference(root);
|
||||||
TelephonyManager tm = TelephonyManager.getDefault();
|
|
||||||
CarrierConfigManager cfgMgr = (CarrierConfigManager)
|
|
||||||
getActivity().getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
|
||||||
PersistableBundle b = cfgMgr.getConfig();
|
|
||||||
if (!mIsAdmin || !isSimIccReady() ||
|
|
||||||
b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
|
||||||
root.removePreference(root.findPreference(KEY_SIM_LOCK));
|
|
||||||
} else {
|
|
||||||
// Disable SIM lock if there is no ready SIM card.
|
|
||||||
root.findPreference(KEY_SIM_LOCK).setEnabled(isSimReady());
|
|
||||||
}
|
|
||||||
if (Settings.System.getInt(getContentResolver(),
|
|
||||||
Settings.System.LOCK_TO_APP_ENABLED, 0) != 0) {
|
|
||||||
root.findPreference(KEY_SCREEN_PINNING).setSummary(
|
|
||||||
getResources().getString(R.string.switch_on_text));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encryption status of device
|
// Encryption status of device
|
||||||
if (LockPatternUtils.isDeviceEncryptionEnabled()) {
|
if (LockPatternUtils.isDeviceEncryptionEnabled()) {
|
||||||
@@ -324,14 +298,8 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
R.string.summary_placeholder);
|
R.string.summary_placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show password
|
|
||||||
mShowPassword = (SwitchPreference) root.findPreference(KEY_SHOW_PASSWORD);
|
|
||||||
|
|
||||||
// Credential storage
|
|
||||||
final UserManager um = (UserManager) getActivity().getSystemService(Context.USER_SERVICE);
|
|
||||||
|
|
||||||
// Advanced Security features
|
// Advanced Security features
|
||||||
initTrustAgentPreference(root, numberOfTrustAgent);
|
mManageTrustAgentsPreferenceController.displayPreference(root);
|
||||||
|
|
||||||
PreferenceGroup securityStatusPreferenceGroup =
|
PreferenceGroup securityStatusPreferenceGroup =
|
||||||
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
|
(PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
|
||||||
@@ -380,23 +348,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
void initTrustAgentPreference(PreferenceScreen root, int numberOfTrustAgent) {
|
|
||||||
Preference manageAgents = root.findPreference(KEY_MANAGE_TRUST_AGENTS);
|
|
||||||
if (manageAgents != null) {
|
|
||||||
if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
|
|
||||||
manageAgents.setEnabled(false);
|
|
||||||
manageAgents.setSummary(R.string.disabled_because_no_backup_security);
|
|
||||||
} else if (numberOfTrustAgent > 0) {
|
|
||||||
manageAgents.setSummary(getActivity().getResources().getQuantityString(
|
|
||||||
R.plurals.manage_trust_agents_summary_on,
|
|
||||||
numberOfTrustAgent, numberOfTrustAgent));
|
|
||||||
} else {
|
|
||||||
manageAgents.setSummary(R.string.manage_trust_agents_summary);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void setLockscreenPreferencesSummary(PreferenceGroup group) {
|
void setLockscreenPreferencesSummary(PreferenceGroup group) {
|
||||||
final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES);
|
final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES);
|
||||||
@@ -411,8 +362,9 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
* The preference must be a RestrictedPreference.
|
* The preference must be a RestrictedPreference.
|
||||||
*/
|
*/
|
||||||
private void disableIfPasswordQualityManaged(String preferenceKey, int userId) {
|
private void disableIfPasswordQualityManaged(String preferenceKey, int userId) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||||
getActivity(), userId);
|
RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
||||||
|
getActivity(), userId);
|
||||||
if (admin != null && mDPM.getPasswordQuality(admin.component, userId) ==
|
if (admin != null && mDPM.getPasswordQuality(admin.component, userId) ==
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
|
DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
|
||||||
final RestrictedPreference pref =
|
final RestrictedPreference pref =
|
||||||
@@ -433,8 +385,8 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
// Return the number of trust agents being added
|
// Return the number of trust agents being added
|
||||||
private int addTrustAgentSettings(PreferenceGroup securityCategory) {
|
private int addTrustAgentSettings(PreferenceGroup securityCategory) {
|
||||||
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
final boolean hasSecurity = mLockPatternUtils.isSecure(MY_USER_ID);
|
||||||
final List<TrustAgentManager.TrustAgentComponentInfo> agents = mTrustAgentManager.getActiveTrustAgents(
|
final List<TrustAgentManager.TrustAgentComponentInfo> agents =
|
||||||
getActivity(), mLockPatternUtils);
|
mTrustAgentManager.getActiveTrustAgents(getActivity(), mLockPatternUtils);
|
||||||
for (TrustAgentManager.TrustAgentComponentInfo agent : agents) {
|
for (TrustAgentManager.TrustAgentComponentInfo agent : agents) {
|
||||||
final RestrictedPreference trustAgentPreference =
|
final RestrictedPreference trustAgentPreference =
|
||||||
new RestrictedPreference(securityCategory.getContext());
|
new RestrictedPreference(securityCategory.getContext());
|
||||||
@@ -458,43 +410,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
return agents.size();
|
return agents.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return true if a there is a Slot that has Icc.
|
|
||||||
*/
|
|
||||||
private boolean isSimIccReady() {
|
|
||||||
TelephonyManager tm = TelephonyManager.getDefault();
|
|
||||||
final List<SubscriptionInfo> subInfoList =
|
|
||||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
|
||||||
|
|
||||||
if (subInfoList != null) {
|
|
||||||
for (SubscriptionInfo subInfo : subInfoList) {
|
|
||||||
if (tm.hasIccCard(subInfo.getSimSlotIndex())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Return true if a SIM is ready for locking.
|
|
||||||
* TODO: consider adding to TelephonyManager or SubscritpionManasger.
|
|
||||||
*/
|
|
||||||
private boolean isSimReady() {
|
|
||||||
final List<SubscriptionInfo> subInfoList =
|
|
||||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
|
||||||
if (subInfoList != null) {
|
|
||||||
for (SubscriptionInfo subInfo : subInfoList) {
|
|
||||||
final int simState = TelephonyManager.getDefault()
|
|
||||||
.getSimState(subInfo.getSimSlotIndex());
|
|
||||||
if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
|
|
||||||
(simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onGearClick(GearPreference p) {
|
public void onGearClick(GearPreference p) {
|
||||||
if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
|
if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
|
||||||
@@ -524,12 +439,10 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateUnificationPreference();
|
updateUnificationPreference();
|
||||||
|
final Preference showPasswordPref = getPreferenceScreen().findPreference(
|
||||||
if (mShowPassword != null) {
|
mShowPasswordPreferenceController.getPreferenceKey());
|
||||||
mShowPassword.setChecked(Settings.System.getInt(getContentResolver(),
|
showPasswordPref.setOnPreferenceChangeListener(mShowPasswordPreferenceController);
|
||||||
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0);
|
mShowPasswordPreferenceController.updateState(showPasswordPref);
|
||||||
}
|
|
||||||
|
|
||||||
mLocationController.updateSummary();
|
mLocationController.updateSummary();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,7 +494,7 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
mTrustAgentClickIntent = preference.getIntent();
|
mTrustAgentClickIntent = preference.getIntent();
|
||||||
boolean confirmationLaunched = helper.launchConfirmationActivity(
|
boolean confirmationLaunched = helper.launchConfirmationActivity(
|
||||||
CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
|
CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
|
||||||
if (!confirmationLaunched&& mTrustAgentClickIntent != null) {
|
if (!confirmationLaunched && mTrustAgentClickIntent != null) {
|
||||||
// If this returns false, it means no password confirmation is required.
|
// If this returns false, it means no password confirmation is required.
|
||||||
startActivity(mTrustAgentClickIntent);
|
startActivity(mTrustAgentClickIntent);
|
||||||
mTrustAgentClickIntent = null;
|
mTrustAgentClickIntent = null;
|
||||||
@@ -715,15 +628,11 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
R.string.unlock_set_unlock_launch_picker_title);
|
R.string.unlock_set_unlock_launch_picker_title);
|
||||||
final ChooseLockSettingsHelper helper =
|
final ChooseLockSettingsHelper helper =
|
||||||
new ChooseLockSettingsHelper(getActivity(), this);
|
new ChooseLockSettingsHelper(getActivity(), this);
|
||||||
if(!helper.launchConfirmationActivity(
|
if (!helper.launchConfirmationActivity(
|
||||||
UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
|
UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
|
||||||
ununifyLocks();
|
ununifyLocks();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (KEY_SHOW_PASSWORD.equals(key)) {
|
|
||||||
Settings.System.putInt(getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
|
|
||||||
((Boolean) value) ? 1 : 0);
|
|
||||||
lockPatternUtils.setVisiblePasswordEnabled((Boolean) value, MY_USER_ID);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -788,8 +697,9 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPasswordManaged(int userId, Context context, DevicePolicyManager dpm) {
|
private boolean isPasswordManaged(int userId, Context context, DevicePolicyManager dpm) {
|
||||||
final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
final RestrictedLockUtils.EnforcedAdmin admin =
|
||||||
context, userId);
|
RestrictedLockUtils.checkIfPasswordQualityIsSet(
|
||||||
|
context, userId);
|
||||||
return admin != null && dpm.getPasswordQuality(admin.component, userId) ==
|
return admin != null && dpm.getPasswordQuality(admin.component, userId) ==
|
||||||
DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
|
||||||
}
|
}
|
||||||
@@ -847,20 +757,13 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
public List<String> getNonIndexableKeys(Context context) {
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
final List<String> keys = super.getNonIndexableKeys(context);
|
||||||
|
final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
|
||||||
|
|
||||||
LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
|
new SimLockPreferenceController(context).updateNonIndexableKeys(keys);
|
||||||
|
|
||||||
// Do not display SIM lock for devices without an Icc card
|
|
||||||
final UserManager um = UserManager.get(context);
|
|
||||||
final TelephonyManager tm = TelephonyManager.from(context);
|
|
||||||
if (!um.isAdminUser() || !tm.hasIccCard()) {
|
|
||||||
keys.add(KEY_SIM_LOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TrustAgent settings disappear when the user has no primary security.
|
// TrustAgent settings disappear when the user has no primary security.
|
||||||
if (!lockPatternUtils.isSecure(MY_USER_ID)) {
|
if (!lockPatternUtils.isSecure(MY_USER_ID)) {
|
||||||
keys.add(KEY_TRUST_AGENT);
|
keys.add(KEY_TRUST_AGENT);
|
||||||
keys.add(KEY_MANAGE_TRUST_AGENTS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(new EnterprisePrivacyPreferenceController(context))
|
if (!(new EnterprisePrivacyPreferenceController(context))
|
||||||
@@ -873,7 +776,6 @@ public class SecuritySettingsV2 extends DashboardFragment
|
|||||||
// Duplicates between parent-child
|
// Duplicates between parent-child
|
||||||
keys.add(KEY_LOCATION);
|
keys.add(KEY_LOCATION);
|
||||||
keys.add(KEY_ENCRYPTION_AND_CREDENTIALS);
|
keys.add(KEY_ENCRYPTION_AND_CREDENTIALS);
|
||||||
keys.add(KEY_SCREEN_PINNING);
|
|
||||||
keys.add(KEY_LOCATION_SCANNING);
|
keys.add(KEY_LOCATION_SCANNING);
|
||||||
|
|
||||||
return keys;
|
return keys;
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.core.TogglePreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
|
||||||
|
public class ShowPasswordPreferenceController extends TogglePreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_SHOW_PASSWORD = "show_password";
|
||||||
|
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||||
|
private final LockPatternUtils mLockPatternUtils;
|
||||||
|
|
||||||
|
public ShowPasswordPreferenceController(Context context) {
|
||||||
|
super(context, KEY_SHOW_PASSWORD);
|
||||||
|
mLockPatternUtils = FeatureFactory.getFactory(context)
|
||||||
|
.getSecurityFeatureProvider()
|
||||||
|
.getLockPatternUtils(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isChecked() {
|
||||||
|
return Settings.System.getInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.TEXT_SHOW_PASSWORD, 1) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setChecked(boolean isChecked) {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
|
||||||
|
isChecked ? 1 : 0);
|
||||||
|
mLockPatternUtils.setVisiblePasswordEnabled(isChecked, MY_USER_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.telephony.CarrierConfigManager;
|
||||||
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class SimLockPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
private static final String KEY_SIM_LOCK = "sim_lock_settings";
|
||||||
|
|
||||||
|
private final CarrierConfigManager mCarrierConfigManager;
|
||||||
|
private final UserManager mUserManager;
|
||||||
|
private final SubscriptionManager mSubscriptionManager;
|
||||||
|
private final TelephonyManager mTelephonyManager;
|
||||||
|
|
||||||
|
public SimLockPreferenceController(Context context) {
|
||||||
|
super(context, KEY_SIM_LOCK);
|
||||||
|
mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
|
||||||
|
mCarrierConfigManager = (CarrierConfigManager)
|
||||||
|
mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
|
||||||
|
mSubscriptionManager = (SubscriptionManager) context
|
||||||
|
.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
|
||||||
|
mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
final PersistableBundle b = mCarrierConfigManager.getConfig();
|
||||||
|
final boolean IsAdmin = mUserManager.isAdminUser();
|
||||||
|
if (!IsAdmin || !isSimIccReady() ||
|
||||||
|
b.getBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL)) {
|
||||||
|
return DISABLED_FOR_USER;
|
||||||
|
}
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (preference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Disable SIM lock if there is no ready SIM card.
|
||||||
|
preference.setEnabled(isSimReady());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return true if a SIM is ready for locking.
|
||||||
|
* TODO: consider adding to TelephonyManager or SubscritpionManasger.
|
||||||
|
*/
|
||||||
|
private boolean isSimReady() {
|
||||||
|
final List<SubscriptionInfo> subInfoList =
|
||||||
|
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||||
|
if (subInfoList != null) {
|
||||||
|
for (SubscriptionInfo subInfo : subInfoList) {
|
||||||
|
final int simState = mTelephonyManager.getSimState(subInfo.getSimSlotIndex());
|
||||||
|
if ((simState != TelephonyManager.SIM_STATE_ABSENT) &&
|
||||||
|
(simState != TelephonyManager.SIM_STATE_UNKNOWN)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if a there is a Slot that has Icc
|
||||||
|
*/
|
||||||
|
private boolean isSimIccReady() {
|
||||||
|
final List<SubscriptionInfo> subInfoList =
|
||||||
|
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||||
|
|
||||||
|
if (subInfoList != null) {
|
||||||
|
for (SubscriptionInfo subInfo : subInfoList) {
|
||||||
|
if (mTelephonyManager.hasIccCard(subInfo.getSimSlotIndex())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security.trustagent;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.support.annotation.VisibleForTesting;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
|
import com.android.settings.security.SecurityFeatureProvider;
|
||||||
|
|
||||||
|
public class ManageTrustAgentsPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String KEY_MANAGE_TRUST_AGENTS = "manage_trust_agents";
|
||||||
|
private static final int MY_USER_ID = UserHandle.myUserId();
|
||||||
|
|
||||||
|
private final LockPatternUtils mLockPatternUtils;
|
||||||
|
private TrustAgentManager mTrustAgentManager;
|
||||||
|
|
||||||
|
public ManageTrustAgentsPreferenceController(Context context) {
|
||||||
|
super(context, KEY_MANAGE_TRUST_AGENTS);
|
||||||
|
final SecurityFeatureProvider securityFeatureProvider = FeatureFactory.getFactory(context)
|
||||||
|
.getSecurityFeatureProvider();
|
||||||
|
mLockPatternUtils = securityFeatureProvider.getLockPatternUtils(context);
|
||||||
|
mTrustAgentManager = securityFeatureProvider.getTrustAgentManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
final Preference preference = screen.findPreference(getPreferenceKey());
|
||||||
|
if (preference == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final int numberOfTrustAgent = getTrustAgentCount();
|
||||||
|
if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
|
||||||
|
preference.setEnabled(false);
|
||||||
|
preference.setSummary(R.string.disabled_because_no_backup_security);
|
||||||
|
} else if (numberOfTrustAgent > 0) {
|
||||||
|
preference.setSummary(mContext.getResources().getQuantityString(
|
||||||
|
R.plurals.manage_trust_agents_summary_on,
|
||||||
|
numberOfTrustAgent, numberOfTrustAgent));
|
||||||
|
} else {
|
||||||
|
preference.setSummary(R.string.manage_trust_agents_summary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getTrustAgentCount() {
|
||||||
|
return mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils).size();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,13 +28,10 @@ import static org.mockito.Mockito.verify;
|
|||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.os.Bundle;
|
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@@ -46,7 +43,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.SettingsActivity;
|
import com.android.settings.SettingsActivity;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.dashboard.conditional.Condition;
|
import com.android.settings.dashboard.conditional.Condition;
|
||||||
import com.android.settings.dashboard.conditional.ConditionAdapter;
|
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
@@ -94,12 +90,6 @@ public class DashboardAdapterTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mFactory = FakeFeatureFactory.setupForTest();
|
mFactory = FakeFeatureFactory.setupForTest();
|
||||||
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
|
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
|
||||||
when(mFactory.suggestionsFeatureProvider
|
|
||||||
.getSuggestionIdentifier(any(Context.class), any(Tile.class)))
|
|
||||||
.thenAnswer(invocation -> {
|
|
||||||
final Object[] args = invocation.getArguments();
|
|
||||||
return ((Tile) args[1]).intent.getComponent().getPackageName();
|
|
||||||
});
|
|
||||||
|
|
||||||
when(mContext.getResources()).thenReturn(mResources);
|
when(mContext.getResources()).thenReturn(mResources);
|
||||||
when(mResources.getQuantityString(any(int.class), any(int.class), any()))
|
when(mResources.getQuantityString(any(int.class), any(int.class), any()))
|
||||||
@@ -108,14 +98,14 @@ public class DashboardAdapterTest {
|
|||||||
mConditionList = new ArrayList<>();
|
mConditionList = new ArrayList<>();
|
||||||
mConditionList.add(mCondition);
|
mConditionList.add(mCondition);
|
||||||
when(mCondition.shouldShow()).thenReturn(true);
|
when(mCondition.shouldShow()).thenReturn(true);
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, null, mConditionList, null, null, null);
|
mDashboardAdapter = new DashboardAdapter(mContext, null, mConditionList, null, null);
|
||||||
mSuggestionHeaderData = new DashboardData.SuggestionConditionHeaderData(mConditionList, 1);
|
mSuggestionHeaderData = new DashboardData.SuggestionConditionHeaderData(mConditionList, 1);
|
||||||
when(mView.getTag()).thenReturn(mCondition);
|
when(mView.getTag()).thenReturn(mCondition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionsLogs_nullSuggestionsList_shouldNotCrash() {
|
public void testSuggestionsLogs_nullSuggestionsList_shouldNotCrash() {
|
||||||
setupSuggestions(makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4", "pkg5"));
|
setupSuggestions(makeSuggestionsV2("pkg1", "pkg2", "pkg3", "pkg4", "pkg5"));
|
||||||
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
mDashboardAdapter.onBindSuggestionConditionHeader(mSuggestionHolder, mSuggestionHeaderData);
|
||||||
|
|
||||||
// set suggestions to null
|
// set suggestions to null
|
||||||
@@ -131,9 +121,9 @@ public class DashboardAdapterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
|
public void testSuggestionDismissed_notOnlySuggestion_updateSuggestionOnly() {
|
||||||
final DashboardAdapter adapter =
|
final DashboardAdapter adapter =
|
||||||
spy(new DashboardAdapter(mContext, null, null, null, null, null));
|
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||||
final List<Tile> suggestions = makeSuggestions("pkg1", "pkg2", "pkg3");
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3");
|
||||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
adapter.setSuggestions(suggestions);
|
||||||
|
|
||||||
final RecyclerView data = mock(RecyclerView.class);
|
final RecyclerView data = mock(RecyclerView.class);
|
||||||
when(data.getResources()).thenReturn(mResources);
|
when(data.getResources()).thenReturn(mResources);
|
||||||
@@ -150,7 +140,7 @@ public class DashboardAdapterTest {
|
|||||||
final DashboardData dashboardData = adapter.mDashboardData;
|
final DashboardData dashboardData = adapter.mDashboardData;
|
||||||
reset(adapter); // clear interactions tracking
|
reset(adapter); // clear interactions tracking
|
||||||
|
|
||||||
final Tile suggestionToRemove = suggestions.get(1);
|
final Suggestion suggestionToRemove = suggestions.get(1);
|
||||||
adapter.onSuggestionDismissed(suggestionToRemove);
|
adapter.onSuggestionDismissed(suggestionToRemove);
|
||||||
|
|
||||||
assertThat(adapter.mDashboardData).isEqualTo(dashboardData);
|
assertThat(adapter.mDashboardData).isEqualTo(dashboardData);
|
||||||
@@ -166,12 +156,11 @@ public class DashboardAdapterTest {
|
|||||||
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
||||||
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
||||||
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
||||||
final List<Tile> suggestions =
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1", "pkg2", "pkg3", "pkg4");
|
||||||
makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4");
|
|
||||||
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /*savedInstance */,
|
final DashboardAdapter adapter = spy(new DashboardAdapter(mContext, null /*savedInstance */,
|
||||||
null /* conditions */, null /* suggestionParser */,
|
null /* conditions */,
|
||||||
null /* suggestionControllerMixin */, null /* callback */));
|
null /* suggestionControllerMixin */, null /* callback */));
|
||||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
adapter.setSuggestions(suggestions);
|
||||||
adapter.onBindConditionAndSuggestion(
|
adapter.onBindConditionAndSuggestion(
|
||||||
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
||||||
// default mode, only displaying 2 suggestions
|
// default mode, only displaying 2 suggestions
|
||||||
@@ -180,16 +169,16 @@ public class DashboardAdapterTest {
|
|||||||
|
|
||||||
// verify operations that access the lists will not cause ConcurrentModificationException
|
// verify operations that access the lists will not cause ConcurrentModificationException
|
||||||
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
|
assertThat(holder.data.getAdapter().getItemCount()).isEqualTo(1);
|
||||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
adapter.setSuggestions(suggestions);
|
||||||
// should not crash
|
// should not crash
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
public void testSuggestionDismissed_onlySuggestion_updateDashboardData() {
|
||||||
DashboardAdapter adapter =
|
DashboardAdapter adapter =
|
||||||
spy(new DashboardAdapter(mContext, null, null, null, null, null));
|
spy(new DashboardAdapter(mContext, null, null, null, null));
|
||||||
final List<Tile> suggestions = makeSuggestions("pkg1");
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||||
adapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
adapter.setSuggestions(suggestions);
|
||||||
final DashboardData dashboardData = adapter.mDashboardData;
|
final DashboardData dashboardData = adapter.mDashboardData;
|
||||||
reset(adapter); // clear interactions tracking
|
reset(adapter); // clear interactions tracking
|
||||||
|
|
||||||
@@ -199,22 +188,6 @@ public class DashboardAdapterTest {
|
|||||||
verify(adapter).notifyDashboardDataChanged(any());
|
verify(adapter).notifyDashboardDataChanged(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSetCategoriesAndSuggestions_iconTinted() {
|
|
||||||
TypedArray mockTypedArray = mock(TypedArray.class);
|
|
||||||
doReturn(mockTypedArray).when(mContext).obtainStyledAttributes(any(int[].class));
|
|
||||||
doReturn(0x89000000).when(mockTypedArray).getColor(anyInt(), anyInt());
|
|
||||||
|
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
|
||||||
Icon mockIcon = mock(Icon.class);
|
|
||||||
packages.get(0).isIconTintable = true;
|
|
||||||
packages.get(0).icon = mockIcon;
|
|
||||||
|
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, packages);
|
|
||||||
|
|
||||||
verify(mockIcon).setTint(eq(0x89000000));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetCategories_iconTinted() {
|
public void testSetCategories_iconTinted() {
|
||||||
TypedArray mockTypedArray = mock(TypedArray.class);
|
TypedArray mockTypedArray = mock(TypedArray.class);
|
||||||
@@ -233,49 +206,14 @@ public class DashboardAdapterTest {
|
|||||||
verify(mockIcon).setTint(eq(0x89000000));
|
verify(mockIcon).setTint(eq(0x89000000));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSetCategoriesAndSuggestions_limitSuggestionSize() {
|
|
||||||
List<Tile> packages =
|
|
||||||
makeSuggestions("pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7");
|
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, packages);
|
|
||||||
|
|
||||||
assertThat(mDashboardAdapter.mDashboardData.getSuggestions().size())
|
|
||||||
.isEqualTo(DashboardAdapter.MAX_SUGGESTION_TO_SHOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBindConditionAndSuggestion_shouldSetSuggestionAdapterAndNoCrash() {
|
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null, null);
|
|
||||||
final List<Tile> suggestions = makeSuggestions("pkg1");
|
|
||||||
final DashboardCategory category = new DashboardCategory();
|
|
||||||
category.addTile(mock(Tile.class));
|
|
||||||
|
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
|
|
||||||
|
|
||||||
final RecyclerView data = mock(RecyclerView.class);
|
|
||||||
when(data.getResources()).thenReturn(mResources);
|
|
||||||
when(data.getContext()).thenReturn(mContext);
|
|
||||||
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
|
|
||||||
final View itemView = mock(View.class);
|
|
||||||
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
|
||||||
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
|
||||||
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindConditionAndSuggestion(
|
|
||||||
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
|
||||||
|
|
||||||
verify(data).setAdapter(any(SuggestionAdapter.class));
|
|
||||||
// should not crash
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindConditionAndSuggestion_v2_shouldSetSuggestionAdapterAndNoCrash() {
|
public void testBindConditionAndSuggestion_v2_shouldSetSuggestionAdapterAndNoCrash() {
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null, null);
|
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||||
final DashboardCategory category = new DashboardCategory();
|
final DashboardCategory category = new DashboardCategory();
|
||||||
category.addTile(mock(Tile.class));
|
category.addTile(mock(Tile.class));
|
||||||
|
|
||||||
mDashboardAdapter.setSuggestionsV2(suggestions);
|
mDashboardAdapter.setSuggestions(suggestions);
|
||||||
|
|
||||||
final RecyclerView data = mock(RecyclerView.class);
|
final RecyclerView data = mock(RecyclerView.class);
|
||||||
when(data.getResources()).thenReturn(mResources);
|
when(data.getResources()).thenReturn(mResources);
|
||||||
@@ -293,50 +231,6 @@ public class DashboardAdapterTest {
|
|||||||
// should not crash
|
// should not crash
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
|
|
||||||
final Bundle savedInstance = new Bundle();
|
|
||||||
savedInstance.putInt(DashboardAdapter.STATE_SUGGESTION_CONDITION_MODE,
|
|
||||||
DashboardData.HEADER_MODE_FULLY_EXPANDED);
|
|
||||||
mDashboardAdapter = new DashboardAdapter(mContext, savedInstance, mConditionList,
|
|
||||||
null /* SuggestionParser */, null /* suggestionControllerMixin */,
|
|
||||||
null /* SuggestionDismissController.Callback */);
|
|
||||||
|
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
|
||||||
final DashboardCategory category = new DashboardCategory();
|
|
||||||
category.addTile(mock(Tile.class));
|
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(category, suggestions);
|
|
||||||
|
|
||||||
final RecyclerView data = mock(RecyclerView.class);
|
|
||||||
when(data.getResources()).thenReturn(mResources);
|
|
||||||
when(data.getContext()).thenReturn(mContext);
|
|
||||||
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
|
|
||||||
final View itemView = mock(View.class);
|
|
||||||
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
|
||||||
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
|
||||||
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
|
||||||
|
|
||||||
mDashboardAdapter.onBindConditionAndSuggestion(
|
|
||||||
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
|
||||||
|
|
||||||
verify(data).setAdapter(any(ConditionAdapter.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated in favor of {@link #makeSuggestionsV2(String...)}
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
private List<Tile> makeSuggestions(String... pkgNames) {
|
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
|
||||||
for (String pkgName : pkgNames) {
|
|
||||||
Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent("action");
|
|
||||||
suggestion.intent.setComponent(new ComponentName(pkgName, "cls"));
|
|
||||||
suggestions.add(suggestion);
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||||
final List<Suggestion> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
for (String pkgName : pkgNames) {
|
for (String pkgName : pkgNames) {
|
||||||
@@ -348,13 +242,11 @@ public class DashboardAdapterTest {
|
|||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSuggestions(List<Tile> suggestions) {
|
private void setupSuggestions(List<Suggestion> suggestions) {
|
||||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
|
||||||
final Context context = RuntimeEnvironment.application;
|
final Context context = RuntimeEnvironment.application;
|
||||||
|
mDashboardAdapter.setSuggestions(suggestions);
|
||||||
mSuggestionHolder = new DashboardAdapter.SuggestionAndConditionHeaderHolder(
|
mSuggestionHolder = new DashboardAdapter.SuggestionAndConditionHeaderHolder(
|
||||||
LayoutInflater.from(context).inflate(
|
LayoutInflater.from(context).inflate(
|
||||||
R.layout.suggestion_condition_header, new RelativeLayout(context), true));
|
R.layout.suggestion_condition_header, new RelativeLayout(context), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,10 +23,11 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.PendingIntent;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v7.util.DiffUtil;
|
import android.support.v7.util.DiffUtil;
|
||||||
import android.support.v7.util.ListUpdateCallback;
|
import android.support.v7.util.ListUpdateCallback;
|
||||||
import android.widget.RemoteViews;
|
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.dashboard.conditional.AirplaneModeCondition;
|
import com.android.settings.dashboard.conditional.AirplaneModeCondition;
|
||||||
@@ -61,11 +62,10 @@ public class DashboardDataTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private Tile mTestCategoryTile;
|
private Tile mTestCategoryTile;
|
||||||
@Mock
|
@Mock
|
||||||
private Tile mTestSuggestion;
|
|
||||||
@Mock
|
|
||||||
private Condition mTestCondition;
|
private Condition mTestCondition;
|
||||||
@Mock
|
@Mock
|
||||||
private Condition mSecondCondition; // condition used to test insert in DiffUtil
|
private Condition mSecondCondition; // condition used to test insert in DiffUtil
|
||||||
|
private Suggestion mTestSuggestion;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void SetUp() {
|
public void SetUp() {
|
||||||
@@ -74,8 +74,11 @@ public class DashboardDataTest {
|
|||||||
mDashboardCategory = new DashboardCategory();
|
mDashboardCategory = new DashboardCategory();
|
||||||
|
|
||||||
// Build suggestions
|
// Build suggestions
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
mTestSuggestion.title = TEST_SUGGESTION_TITLE;
|
mTestSuggestion = new Suggestion.Builder("pkg")
|
||||||
|
.setTitle(TEST_SUGGESTION_TITLE)
|
||||||
|
.setPendingIntent(mock(PendingIntent.class))
|
||||||
|
.build();
|
||||||
suggestions.add(mTestSuggestion);
|
suggestions.add(mTestSuggestion);
|
||||||
|
|
||||||
// Build oneItemConditions
|
// Build oneItemConditions
|
||||||
@@ -227,8 +230,7 @@ public class DashboardDataTest {
|
|||||||
final List<Condition> oneItemConditions = new ArrayList<>();
|
final List<Condition> oneItemConditions = new ArrayList<>();
|
||||||
when(mTestCondition.shouldShow()).thenReturn(true);
|
when(mTestCondition.shouldShow()).thenReturn(true);
|
||||||
oneItemConditions.add(mTestCondition);
|
oneItemConditions.add(mTestCondition);
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
mTestSuggestion.title = TEST_SUGGESTION_TITLE;
|
|
||||||
suggestions.add(mTestSuggestion);
|
suggestions.add(mTestSuggestion);
|
||||||
|
|
||||||
final DashboardData oldData = new DashboardData.Builder()
|
final DashboardData oldData = new DashboardData.Builder()
|
||||||
@@ -261,20 +263,16 @@ public class DashboardDataTest {
|
|||||||
public void testDiffUtil_typeSuggestedContainer_ResultDataNothingChanged() {
|
public void testDiffUtil_typeSuggestedContainer_ResultDataNothingChanged() {
|
||||||
//Build testResultData
|
//Build testResultData
|
||||||
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
final List<ListUpdateResult.ResultData> testResultData = new ArrayList<>();
|
||||||
testResultData.add(new ListUpdateResult.ResultData(
|
|
||||||
ListUpdateResult.ResultData.TYPE_OPERATION_CHANGE, 0, 1));
|
|
||||||
Tile tile = new Tile();
|
|
||||||
tile.remoteViews = mock(RemoteViews.class);
|
|
||||||
|
|
||||||
DashboardData prevData = new DashboardData.Builder()
|
DashboardData prevData = new DashboardData.Builder()
|
||||||
.setConditions(null)
|
.setConditions(null)
|
||||||
.setCategory(null)
|
.setCategory(null)
|
||||||
.setSuggestions(Arrays.asList(tile))
|
.setSuggestions(Arrays.asList(mTestSuggestion))
|
||||||
.build();
|
.build();
|
||||||
DashboardData currentData = new DashboardData.Builder()
|
DashboardData currentData = new DashboardData.Builder()
|
||||||
.setConditions(null)
|
.setConditions(null)
|
||||||
.setCategory(null)
|
.setCategory(null)
|
||||||
.setSuggestions(Arrays.asList(tile))
|
.setSuggestions(Arrays.asList(mTestSuggestion))
|
||||||
.build();
|
.build();
|
||||||
testDiffUtil(prevData, currentData, testResultData);
|
testDiffUtil(prevData, currentData, testResultData);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,25 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.dashboard;
|
package com.android.settings.dashboard;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
|
||||||
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
|
||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.nullable;
|
import static org.mockito.ArgumentMatchers.nullable;
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
@@ -45,6 +26,27 @@ import static org.mockito.Mockito.spy;
|
|||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.service.settings.suggestions.Suggestion;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||||
|
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
@@ -63,11 +65,13 @@ public class DashboardSummaryTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private SummaryLoader mSummaryLoader;
|
private SummaryLoader mSummaryLoader;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
private DashboardSummary mSummary;
|
private DashboardSummary mSummary;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
mSummary = spy(new DashboardSummary());
|
mSummary = spy(new DashboardSummary());
|
||||||
ReflectionHelpers.setField(mSummary, "mAdapter", mAdapter);
|
ReflectionHelpers.setField(mSummary, "mAdapter", mAdapter);
|
||||||
ReflectionHelpers.setField(mSummary, "mDashboardFeatureProvider",
|
ReflectionHelpers.setField(mSummary, "mDashboardFeatureProvider",
|
||||||
@@ -79,9 +83,10 @@ public class DashboardSummaryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateCategoryAndSuggestion_shouldGetCategoryFromFeatureProvider() {
|
public void updateCategory_shouldGetCategoryFromFeatureProvider() {
|
||||||
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
doReturn(mock(Activity.class)).when(mSummary).getActivity();
|
||||||
mSummary.updateCategoryAndSuggestion(null);
|
mSummary.onAttach(mContext);
|
||||||
|
mSummary.updateCategory();
|
||||||
|
|
||||||
verify(mSummaryLoader).updateSummaryToCache(nullable(DashboardCategory.class));
|
verify(mSummaryLoader).updateSummaryToCache(nullable(DashboardCategory.class));
|
||||||
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
|
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
|
||||||
@@ -135,7 +140,7 @@ public class DashboardSummaryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onSuggestionDismissed_shouldNotRebuildUI() {
|
public void onSuggestionDismissed_shouldNotRebuildUI() {
|
||||||
mSummary.onSuggestionDismissed(mock(Tile.class));
|
mSummary.onSuggestionDismissed(mock(Suggestion.class));
|
||||||
verify(mSummary, never()).rebuildUI();
|
verify(mSummary, never()).rebuildUI();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class EventStoreTest {
|
|
||||||
|
|
||||||
private EventStore mEventStore;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mEventStore = new EventStore(RuntimeEnvironment.application);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWriteRead() {
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_SHOWN);
|
|
||||||
long timeMs = System.currentTimeMillis();
|
|
||||||
assertThat(mEventStore.readMetric("pkg", EventStore.EVENT_SHOWN, EventStore.METRIC_COUNT))
|
|
||||||
.isEqualTo(1);
|
|
||||||
assertThat(Math.abs(timeMs - mEventStore
|
|
||||||
.readMetric("pkg", EventStore.EVENT_SHOWN, EventStore.METRIC_LAST_EVENT_TIME)) < 10000)
|
|
||||||
.isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWriteRead_shouldHaveLatestValues() {
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_DISMISSED);
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_DISMISSED);
|
|
||||||
assertThat(
|
|
||||||
mEventStore.readMetric("pkg", EventStore.EVENT_DISMISSED, EventStore.METRIC_COUNT))
|
|
||||||
.isEqualTo(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWriteRead_shouldReturnDefaultIfNotAvailable() {
|
|
||||||
assertThat(mEventStore.readMetric("pkg", EventStore.EVENT_SHOWN, EventStore.METRIC_COUNT))
|
|
||||||
.isEqualTo(0);
|
|
||||||
assertThat(
|
|
||||||
mEventStore
|
|
||||||
.readMetric("pkg", EventStore.EVENT_SHOWN, EventStore.METRIC_LAST_EVENT_TIME))
|
|
||||||
.isEqualTo(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -16,28 +16,18 @@
|
|||||||
package com.android.settings.dashboard.suggestions;
|
package com.android.settings.dashboard.suggestions;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
import static org.mockito.Mockito.doReturn;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.graphics.drawable.Icon;
|
import android.graphics.drawable.Icon;
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.view.ContextThemeWrapper;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RemoteViews;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -56,7 +46,6 @@ import org.mockito.Mock;
|
|||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -111,37 +100,18 @@ public class SuggestionAdapterTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getItemCount_shouldReturnListSize() {
|
public void getItemCount_shouldReturnListSize() {
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
mOneSuggestionV2, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
||||||
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
mTwoSuggestions, null /* suggestionV2 */, new ArrayList<>());
|
mTwoSuggestionsV2, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getItemCount_v2_shouldReturnListSize() {
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
|
||||||
null /* suggestions */, mOneSuggestionV2, new ArrayList<>());
|
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
|
||||||
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
|
||||||
null /* suggestions */, mTwoSuggestionsV2, new ArrayList<>());
|
|
||||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getItemViewType_shouldReturnSuggestionTile() {
|
public void getItemViewType_shouldReturnSuggestionTile() {
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
mOneSuggestionV2, new ArrayList<>());
|
||||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
|
||||||
.isEqualTo(R.layout.suggestion_tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getItemViewType_v2_shouldReturnSuggestionTile() {
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
|
||||||
null /* suggestions */, mOneSuggestionV2, new ArrayList<>());
|
|
||||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||||
.isEqualTo(R.layout.suggestion_tile);
|
.isEqualTo(R.layout.suggestion_tile);
|
||||||
}
|
}
|
||||||
@@ -155,32 +125,19 @@ public class SuggestionAdapterTest {
|
|||||||
.setSummary("456")
|
.setSummary("456")
|
||||||
.build());
|
.build());
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
null /* suggestions */, suggestions, new ArrayList<>());
|
suggestions, new ArrayList<>());
|
||||||
|
|
||||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||||
.isEqualTo(R.layout.suggestion_tile_with_button);
|
.isEqualTo(R.layout.suggestion_tile_with_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onBindViewHolder_shouldSetListener() {
|
|
||||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
|
||||||
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
|
||||||
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
|
||||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
|
||||||
|
|
||||||
verify(view).setOnClickListener(any(View.OnClickListener.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_shouldLog() {
|
public void onBindViewHolder_shouldLog() {
|
||||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
final View view = spy(LayoutInflater.from(mContext).inflate(
|
||||||
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
||||||
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
||||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||||
null /* suggestionV1*/, mOneSuggestionV2, new ArrayList<>());
|
mOneSuggestionV2, new ArrayList<>());
|
||||||
|
|
||||||
// Bind twice
|
// Bind twice
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
@@ -193,53 +150,10 @@ public class SuggestionAdapterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_shouldInflateRemoteView() {
|
public void onBindViewHolder_itemViewShouldHandleClick()
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
|
||||||
TextView textView = new TextView(RuntimeEnvironment.application);
|
|
||||||
doReturn(textView).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
|
||||||
packages.get(0).remoteViews = remoteViews;
|
|
||||||
setupSuggestions(mActivity, packages, null);
|
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
|
||||||
|
|
||||||
assertThat(textView.getParent()).isSameAs(mSuggestionHolder.itemView);
|
|
||||||
mSuggestionHolder.itemView.performClick();
|
|
||||||
|
|
||||||
verify(mActivity).startSuggestion(any(Intent.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onBindViewHolder_primaryViewShouldHandleClick() {
|
|
||||||
Context context =
|
|
||||||
new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
|
|
||||||
|
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
|
||||||
FrameLayout layout = new FrameLayout(context);
|
|
||||||
Button primary = new Button(context);
|
|
||||||
primary.setId(android.R.id.primary);
|
|
||||||
layout.addView(primary);
|
|
||||||
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
|
||||||
packages.get(0).remoteViews = remoteViews;
|
|
||||||
setupSuggestions(mActivity, packages, null /* suggestionV2 */);
|
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
|
||||||
mSuggestionHolder.itemView.performClick();
|
|
||||||
|
|
||||||
assertThat(ShadowApplication.getInstance().getNextStartedActivity()).isNull();
|
|
||||||
verify(mActivity, never()).startSuggestion(any(Intent.class));
|
|
||||||
|
|
||||||
primary.performClick();
|
|
||||||
|
|
||||||
verify(mActivity).startSuggestion(any(Intent.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onBindViewHolder_v2_itemViewShouldHandleClick()
|
|
||||||
throws PendingIntent.CanceledException {
|
throws PendingIntent.CanceledException {
|
||||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||||
setupSuggestions(mActivity, null /* suggestionV1 */, suggestions);
|
setupSuggestions(mActivity, suggestions);
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||||
mSuggestionHolder.itemView.performClick();
|
mSuggestionHolder.itemView.performClick();
|
||||||
@@ -249,64 +163,21 @@ public class SuggestionAdapterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onBindViewHolder_viewsShouldClearOnRebind() {
|
public void getSuggestions_shouldReturnSuggestionWhenMatch() {
|
||||||
Context context =
|
|
||||||
new ContextThemeWrapper(RuntimeEnvironment.application, R.style.Theme_Settings);
|
|
||||||
|
|
||||||
List<Tile> packages = makeSuggestions("pkg1");
|
|
||||||
RemoteViews remoteViews = mock(RemoteViews.class);
|
|
||||||
FrameLayout layout = new FrameLayout(context);
|
|
||||||
Button primary = new Button(context);
|
|
||||||
primary.setId(android.R.id.primary);
|
|
||||||
layout.addView(primary);
|
|
||||||
doReturn(layout).when(remoteViews).apply(any(Context.class), any(ViewGroup.class));
|
|
||||||
packages.get(0).remoteViews = remoteViews;
|
|
||||||
setupSuggestions(mActivity, packages, null /* suggestionV2 */);
|
|
||||||
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
|
||||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
|
||||||
|
|
||||||
ViewGroup itemView = (ViewGroup) mSuggestionHolder.itemView;
|
|
||||||
assertThat(itemView.getChildCount()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSuggestionsV2_shouldReturnSuggestionWhenMatch() {
|
|
||||||
final List<Suggestion> suggestionsV2 = makeSuggestionsV2("pkg1");
|
final List<Suggestion> suggestionsV2 = makeSuggestionsV2("pkg1");
|
||||||
setupSuggestions(mActivity, null /* suggestionV1 */, suggestionsV2);
|
setupSuggestions(mActivity, suggestionsV2);
|
||||||
|
|
||||||
assertThat(mSuggestionAdapter.getSuggestion(0)).isNull();
|
|
||||||
assertThat(mSuggestionAdapter.getSuggestionsV2(0)).isNotNull();
|
|
||||||
|
|
||||||
List<Tile> suggestionsV1 = makeSuggestions("pkg1");
|
|
||||||
setupSuggestions(mActivity, suggestionsV1, null /* suggestionV2 */);
|
|
||||||
|
|
||||||
assertThat(mSuggestionAdapter.getSuggestionsV2(0)).isNull();
|
|
||||||
assertThat(mSuggestionAdapter.getSuggestion(0)).isNotNull();
|
assertThat(mSuggestionAdapter.getSuggestion(0)).isNotNull();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSuggestions(Context context, List<Tile> suggestions,
|
private void setupSuggestions(Context context, List<Suggestion> suggestionsV2) {
|
||||||
List<Suggestion> suggestionsV2) {
|
|
||||||
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
||||||
suggestions, suggestionsV2, new ArrayList<>());
|
suggestionsV2, new ArrayList<>());
|
||||||
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
|
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
|
||||||
new FrameLayout(RuntimeEnvironment.application),
|
new FrameLayout(RuntimeEnvironment.application),
|
||||||
mSuggestionAdapter.getItemViewType(0));
|
mSuggestionAdapter.getItemViewType(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Tile> makeSuggestions(String... pkgNames) {
|
|
||||||
final List<Tile> suggestions = new ArrayList<>();
|
|
||||||
for (String pkgName : pkgNames) {
|
|
||||||
Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent("action");
|
|
||||||
suggestion.intent.setComponent(new ComponentName(pkgName, "cls"));
|
|
||||||
suggestions.add(suggestion);
|
|
||||||
suggestion.icon = mock(Icon.class);
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||||
final List<Suggestion> suggestions = new ArrayList<>();
|
final List<Suggestion> suggestions = new ArrayList<>();
|
||||||
for (String pkgName : pkgNames) {
|
for (String pkgName : pkgNames) {
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ import com.android.settings.R;
|
|||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -53,8 +51,6 @@ public class SuggestionDismissControllerTest {
|
|||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
@Mock
|
@Mock
|
||||||
private SuggestionParser mSuggestionParser;
|
|
||||||
@Mock
|
|
||||||
private SuggestionControllerMixin mSuggestionControllerMixin;
|
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||||
@Mock
|
@Mock
|
||||||
private SuggestionDismissController.Callback mCallback;
|
private SuggestionDismissController.Callback mCallback;
|
||||||
@@ -70,7 +66,7 @@ public class SuggestionDismissControllerTest {
|
|||||||
when(mRecyclerView.getResources().getDimension(anyInt())).thenReturn(50F);
|
when(mRecyclerView.getResources().getDimension(anyInt())).thenReturn(50F);
|
||||||
|
|
||||||
mController = new SuggestionDismissController(mContext, mRecyclerView,
|
mController = new SuggestionDismissController(mContext, mRecyclerView,
|
||||||
mSuggestionControllerMixin, mSuggestionParser, mCallback);
|
mSuggestionControllerMixin, mCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -108,17 +104,6 @@ public class SuggestionDismissControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void onSwiped_shouldTriggerDismissSuggestion() {
|
public void onSwiped_shouldTriggerDismissSuggestion() {
|
||||||
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
|
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
|
||||||
|
|
||||||
mController.onSwiped(vh, ItemTouchHelper.START);
|
|
||||||
|
|
||||||
verify(mFactory.suggestionsFeatureProvider).dismissSuggestion(
|
|
||||||
eq(mContext), eq(mSuggestionParser), nullable(Tile.class));
|
|
||||||
verify(mCallback).onSuggestionDismissed(nullable(Tile.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void onSwiped_v2_shouldTriggerDismissSuggestion() {
|
|
||||||
final RecyclerView.ViewHolder vh = mock(RecyclerView.ViewHolder.class);
|
|
||||||
when(mCallback.getSuggestionAt(anyInt())).thenReturn(
|
when(mCallback.getSuggestionAt(anyInt())).thenReturn(
|
||||||
new Suggestion.Builder("id").build());
|
new Suggestion.Builder("id").build());
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
@@ -30,34 +29,27 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.hardware.fingerprint.FingerprintManager;
|
import android.hardware.fingerprint.FingerprintManager;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.service.settings.suggestions.Suggestion;
|
import android.service.settings.suggestions.Suggestion;
|
||||||
import android.util.FeatureFlagUtils;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto;
|
import com.android.internal.logging.nano.MetricsProto;
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
import com.android.settings.Settings.NightDisplaySuggestionActivity;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.core.FeatureFlags;
|
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
import com.android.settings.testutils.shadow.SettingsShadowResources;
|
||||||
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
import com.android.settings.testutils.shadow.ShadowSecureSettings;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
import com.android.settingslib.suggestions.SuggestionParser;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Captor;
|
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
@@ -71,26 +63,21 @@ import java.util.List;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION, shadows = {
|
||||||
ShadowSecureSettings.class,
|
ShadowSecureSettings.class,
|
||||||
SettingsShadowResources.class,
|
SettingsShadowResources.class,
|
||||||
SettingsShadowSystemProperties.class
|
|
||||||
})
|
})
|
||||||
public class SuggestionFeatureProviderImplTest {
|
public class SuggestionFeatureProviderImplTest {
|
||||||
|
|
||||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private SuggestionParser mSuggestionParser;
|
|
||||||
@Mock
|
|
||||||
private SuggestionControllerMixin mSuggestionControllerMixin;
|
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||||
@Mock
|
@Mock
|
||||||
private Tile mSuggestion;
|
private Suggestion mSuggestion;
|
||||||
@Mock
|
@Mock
|
||||||
private ActivityManager mActivityManager;
|
private ActivityManager mActivityManager;
|
||||||
@Mock
|
@Mock
|
||||||
private PackageManager mPackageManager;
|
private PackageManager mPackageManager;
|
||||||
@Mock
|
@Mock
|
||||||
private FingerprintManager mFingerprintManager;
|
private FingerprintManager mFingerprintManager;
|
||||||
@Captor
|
|
||||||
private ArgumentCaptor<Pair> mTaggedDataCaptor = ArgumentCaptor.forClass(Pair.class);
|
|
||||||
|
|
||||||
private FakeFeatureFactory mFactory;
|
private FakeFeatureFactory mFactory;
|
||||||
private SuggestionFeatureProviderImpl mProvider;
|
private SuggestionFeatureProviderImpl mProvider;
|
||||||
@@ -103,20 +90,17 @@ public class SuggestionFeatureProviderImplTest {
|
|||||||
// Explicit casting to object due to MockitoCast bug
|
// Explicit casting to object due to MockitoCast bug
|
||||||
when((Object) mContext.getSystemService(FingerprintManager.class))
|
when((Object) mContext.getSystemService(FingerprintManager.class))
|
||||||
.thenReturn(mFingerprintManager);
|
.thenReturn(mFingerprintManager);
|
||||||
|
when(mSuggestion.getId()).thenReturn("test_id");
|
||||||
when(mContext.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
|
when(mContext.getApplicationContext()).thenReturn(RuntimeEnvironment.application);
|
||||||
when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager);
|
when(mContext.getSystemService(Context.ACTIVITY_SERVICE)).thenReturn(mActivityManager);
|
||||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||||
|
|
||||||
mSuggestion.intent = new Intent().setClassName("pkg", "cls");
|
|
||||||
mSuggestion.category = "category";
|
|
||||||
|
|
||||||
mProvider = new SuggestionFeatureProviderImpl(mContext);
|
mProvider = new SuggestionFeatureProviderImpl(mContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
SettingsShadowResources.reset();
|
SettingsShadowResources.reset();
|
||||||
SettingsShadowSystemProperties.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -129,29 +113,18 @@ public class SuggestionFeatureProviderImplTest {
|
|||||||
public void isSuggestionEnabled_isLowMemoryDevice_shouldReturnFalse() {
|
public void isSuggestionEnabled_isLowMemoryDevice_shouldReturnFalse() {
|
||||||
when(mActivityManager.isLowRamDevice()).thenReturn(true);
|
when(mActivityManager.isLowRamDevice()).thenReturn(true);
|
||||||
|
|
||||||
assertThat(mProvider.isSuggestionEnabled(mContext)).isFalse();
|
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void isSuggestionV2Enabled_isNotLowMemoryDevice_sysPropOn_shouldReturnTrue() {
|
public void isSuggestionV2Enabled_isNotLowMemoryDevice_shouldReturnTrue() {
|
||||||
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
when(mActivityManager.isLowRamDevice()).thenReturn(false);
|
||||||
SettingsShadowSystemProperties.set(
|
|
||||||
FeatureFlagUtils.FFLAG_PREFIX + FeatureFlags.SUGGESTIONS_V2, "true");
|
|
||||||
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isTrue();
|
assertThat(mProvider.isSuggestionV2Enabled(mContext)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dismissSuggestion_noParserOrSuggestion_noop() {
|
|
||||||
mProvider.dismissSuggestion(mContext, null, (Tile) null);
|
|
||||||
mProvider.dismissSuggestion(mContext, mSuggestionParser, null);
|
|
||||||
mProvider.dismissSuggestion(mContext, null, mSuggestion);
|
|
||||||
|
|
||||||
verifyZeroInteractions(mFactory.metricsFeatureProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dismissSuggestion_noControllerOrSuggestion_noop() {
|
public void dismissSuggestion_noControllerOrSuggestion_noop() {
|
||||||
mProvider.dismissSuggestion(mContext, null, (Suggestion) null);
|
mProvider.dismissSuggestion(mContext, null, null);
|
||||||
mProvider.dismissSuggestion(mContext, mSuggestionControllerMixin, null);
|
mProvider.dismissSuggestion(mContext, mSuggestionControllerMixin, null);
|
||||||
mProvider.dismissSuggestion(mContext, null, new Suggestion.Builder("id").build());
|
mProvider.dismissSuggestion(mContext, null, new Suggestion.Builder("id").build());
|
||||||
|
|
||||||
@@ -159,82 +132,22 @@ public class SuggestionFeatureProviderImplTest {
|
|||||||
verifyZeroInteractions(mSuggestionControllerMixin);
|
verifyZeroInteractions(mSuggestionControllerMixin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSuggestionIdentifier_samePackage_returnClassName() {
|
|
||||||
final Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent()
|
|
||||||
.setClassName(RuntimeEnvironment.application.getPackageName(), "123");
|
|
||||||
assertThat(mProvider.getSuggestionIdentifier(RuntimeEnvironment.application, suggestion))
|
|
||||||
.isEqualTo("123");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSuggestionIdentifier_differentPackage_returnPackageName() {
|
|
||||||
final Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent()
|
|
||||||
.setClassName(RuntimeEnvironment.application.getPackageName(), "123");
|
|
||||||
assertThat(mProvider.getSuggestionIdentifier(mContext, suggestion))
|
|
||||||
.isEqualTo(RuntimeEnvironment.application.getPackageName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSuggestionIdentifier_nullComponent_shouldNotCrash() {
|
|
||||||
final Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent();
|
|
||||||
assertThat(mProvider.getSuggestionIdentifier(mContext, suggestion))
|
|
||||||
.isNotEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSuggestionIdentifier_nullContext_shouldNotCrash() {
|
|
||||||
final Tile suggestion = new Tile();
|
|
||||||
suggestion.intent = new Intent()
|
|
||||||
.setClassName(RuntimeEnvironment.application.getPackageName(), "123");
|
|
||||||
assertThat(mProvider.getSuggestionIdentifier(null, suggestion))
|
|
||||||
.isNotEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void dismissSuggestion_hasMoreDismissCount_shouldNotDisableComponent() {
|
|
||||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class)))
|
|
||||||
.thenReturn(false);
|
|
||||||
mProvider.dismissSuggestion(mContext, mSuggestionParser, mSuggestion);
|
|
||||||
|
|
||||||
verify(mFactory.metricsFeatureProvider).action(
|
|
||||||
eq(mContext),
|
|
||||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
|
|
||||||
anyString(),
|
|
||||||
mTaggedDataCaptor.capture());
|
|
||||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
|
||||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
|
||||||
verify(mContext, never()).getPackageManager();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dismissSuggestion_noContext_shouldDoNothing() {
|
public void dismissSuggestion_noContext_shouldDoNothing() {
|
||||||
mProvider.dismissSuggestion(null, mSuggestionParser, mSuggestion);
|
mProvider.dismissSuggestion(null, mSuggestionControllerMixin, mSuggestion);
|
||||||
|
|
||||||
verifyZeroInteractions(mFactory.metricsFeatureProvider);
|
verifyZeroInteractions(mFactory.metricsFeatureProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void dismissSuggestion_hasNoMoreDismissCount_shouldDisableComponent() {
|
public void dismissSuggestion_shouldLogAndDismiss() {
|
||||||
when(mSuggestionParser.dismissSuggestion(any(Tile.class)))
|
mProvider.dismissSuggestion(mContext, mSuggestionControllerMixin, mSuggestion);
|
||||||
.thenReturn(true);
|
|
||||||
|
|
||||||
mProvider.dismissSuggestion(mContext, mSuggestionParser, mSuggestion);
|
|
||||||
|
|
||||||
verify(mFactory.metricsFeatureProvider).action(
|
verify(mFactory.metricsFeatureProvider).action(
|
||||||
eq(mContext),
|
eq(mContext),
|
||||||
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
|
eq(MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION),
|
||||||
anyString(),
|
anyString());
|
||||||
mTaggedDataCaptor.capture());
|
verify(mSuggestionControllerMixin).dismissSuggestion(mSuggestion);
|
||||||
assertThat(mTaggedDataCaptor.getAllValues()).containsExactly(
|
|
||||||
Pair.create(MetricsEvent.FIELD_SETTINGS_SMART_SUGGESTIONS_ENABLED, 0));
|
|
||||||
verify(mContext.getPackageManager())
|
|
||||||
.setComponentEnabledSetting(mSuggestion.intent.getComponent(),
|
|
||||||
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
|
|
||||||
PackageManager.DONT_KILL_APP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class SuggestionFeaturizerTest {
|
|
||||||
|
|
||||||
private EventStore mEventStore;
|
|
||||||
private SuggestionFeaturizer mSuggestionFeaturizer;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
mEventStore = new EventStore(RuntimeEnvironment.application);
|
|
||||||
mSuggestionFeaturizer = new SuggestionFeaturizer(mEventStore);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFeaturize_singlePackage() {
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_DISMISSED);
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_SHOWN);
|
|
||||||
mEventStore.writeEvent("pkg", EventStore.EVENT_SHOWN);
|
|
||||||
Map<String, Double> features = mSuggestionFeaturizer.featurize(Arrays.asList("pkg"))
|
|
||||||
.get("pkg");
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_IS_SHOWN)).isEqualTo(1.0);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_IS_DISMISSED)).isEqualTo(1.0);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_IS_CLICKED)).isEqualTo(0.0);
|
|
||||||
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_SHOWN)).isLessThan(1.0);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_DISMISSED))
|
|
||||||
.isLessThan(1.0);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_CLICKED))
|
|
||||||
.isEqualTo(1.0);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_SHOWN_COUNT))
|
|
||||||
.isEqualTo(2.0 / SuggestionFeaturizer.COUNT_NORMALIZATION_FACTOR);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_DISMISSED_COUNT))
|
|
||||||
.isEqualTo(1.0 / SuggestionFeaturizer.COUNT_NORMALIZATION_FACTOR);
|
|
||||||
assertThat(features.get(SuggestionFeaturizer.FEATURE_CLICKED_COUNT)).isEqualTo(0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testFeaturize_multiplePackages() {
|
|
||||||
mEventStore.writeEvent("pkg1", EventStore.EVENT_DISMISSED);
|
|
||||||
mEventStore.writeEvent("pkg2", EventStore.EVENT_SHOWN);
|
|
||||||
mEventStore.writeEvent("pkg1", EventStore.EVENT_SHOWN);
|
|
||||||
Map<String, Map<String, Double>> features = mSuggestionFeaturizer
|
|
||||||
.featurize(Arrays.asList("pkg1", "pkg2"));
|
|
||||||
Map<String, Double> features1 = features.get("pkg1");
|
|
||||||
Map<String, Double> features2 = features.get("pkg2");
|
|
||||||
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_IS_SHOWN)).isEqualTo(1.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_IS_DISMISSED)).isEqualTo(1.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_IS_CLICKED)).isEqualTo(0.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_SHOWN))
|
|
||||||
.isLessThan(1.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_DISMISSED))
|
|
||||||
.isLessThan(1.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_CLICKED))
|
|
||||||
.isEqualTo(1.0);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_SHOWN_COUNT))
|
|
||||||
.isEqualTo(1.0 / SuggestionFeaturizer.COUNT_NORMALIZATION_FACTOR);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_DISMISSED_COUNT))
|
|
||||||
.isEqualTo(1.0 / SuggestionFeaturizer.COUNT_NORMALIZATION_FACTOR);
|
|
||||||
assertThat(features1.get(SuggestionFeaturizer.FEATURE_CLICKED_COUNT)).isEqualTo(0.0);
|
|
||||||
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_IS_SHOWN)).isEqualTo(1.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_IS_DISMISSED)).isEqualTo(0.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_IS_CLICKED)).isEqualTo(0.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_SHOWN))
|
|
||||||
.isLessThan(1.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_DISMISSED))
|
|
||||||
.isEqualTo(1.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_TIME_FROM_LAST_CLICKED))
|
|
||||||
.isEqualTo(1.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_SHOWN_COUNT))
|
|
||||||
.isEqualTo(1.0 / SuggestionFeaturizer.COUNT_NORMALIZATION_FACTOR);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_DISMISSED_COUNT)).isEqualTo(0.0);
|
|
||||||
assertThat(features2.get(SuggestionFeaturizer.FEATURE_CLICKED_COUNT)).isEqualTo(0.0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2017 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.dashboard.suggestions;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
|
||||||
import com.android.settings.TestConfig;
|
|
||||||
import com.android.settingslib.drawer.Tile;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
import static org.mockito.Mockito.same;
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
|
||||||
public class SuggestionRankerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private SuggestionRanker mSuggestionRanker;
|
|
||||||
@Mock
|
|
||||||
private SuggestionFeaturizer mSuggestionFeaturizer;
|
|
||||||
private Map<String, Map<String, Double>> mFeatures;
|
|
||||||
private List<String> mPkgNames;
|
|
||||||
private List<Tile> mSuggestions;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mPkgNames = Arrays.asList("pkg1", "pkg2", "pkg3");
|
|
||||||
mFeatures = new HashMap<String, Map<String, Double>>();
|
|
||||||
mFeatures.put("pkg1", new HashMap<String, Double>());
|
|
||||||
mFeatures.put("pkg2", new HashMap<String, Double>());
|
|
||||||
mFeatures.put("pkg3", new HashMap<String, Double>());
|
|
||||||
mSuggestions = new ArrayList<Tile>() {
|
|
||||||
{
|
|
||||||
add(new Tile());
|
|
||||||
add(new Tile());
|
|
||||||
add(new Tile());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mSuggestionFeaturizer = mock(SuggestionFeaturizer.class);
|
|
||||||
mSuggestionRanker = new SuggestionRanker(mSuggestionFeaturizer);
|
|
||||||
when(mSuggestionFeaturizer.featurize(mPkgNames)).thenReturn(mFeatures);
|
|
||||||
mSuggestionRanker = spy(mSuggestionRanker);
|
|
||||||
when(mSuggestionRanker.getRelevanceMetric(same(mFeatures.get("pkg1")))).thenReturn(0.9);
|
|
||||||
when(mSuggestionRanker.getRelevanceMetric(same(mFeatures.get("pkg2")))).thenReturn(0.1);
|
|
||||||
when(mSuggestionRanker.getRelevanceMetric(same(mFeatures.get("pkg3")))).thenReturn(0.5);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRank() {
|
|
||||||
List<Tile> expectedOrderdList = new ArrayList<Tile>() {
|
|
||||||
{
|
|
||||||
add(mSuggestions.get(0)); // relevance = 0.9
|
|
||||||
add(mSuggestions.get(2)); // relevance = 0.5
|
|
||||||
add(mSuggestions.get(1)); // relevance = 0.1
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mSuggestionRanker.rankSuggestions(mSuggestions, mPkgNames);
|
|
||||||
assertThat(mSuggestions).isEqualTo(expectedOrderdList);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class ScreenPinningPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private ScreenPinningPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
mController = new ScreenPinningPreferenceController(mContext);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.LOCK_TO_APP_ENABLED, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_isOff_shouldDisableOffSummary() {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.LOCK_TO_APP_ENABLED, 0);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.switch_off_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_isOn_shouldDisableOnSummary() {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(),
|
||||||
|
Settings.System.LOCK_TO_APP_ENABLED, 1);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.switch_on_text));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
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.os.UserHandle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class ShowPasswordPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private ShowPasswordPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
mController = new ShowPasswordPreferenceController(mContext);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_settingIsOff_false() {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
|
||||||
|
0);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isChecked_settingIsOn_true() {
|
||||||
|
Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
|
||||||
|
1);
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void changePref_turnOn_shouldChangeSettingTo1() {
|
||||||
|
mController.onPreferenceChange(mPreference, true);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isTrue();
|
||||||
|
verify(mLockPatternUtils).setVisiblePasswordEnabled(true, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void changePref_turnOff_shouldChangeSettingTo0() {
|
||||||
|
mController.onPreferenceChange(mPreference, false);
|
||||||
|
|
||||||
|
assertThat(mController.isChecked()).isFalse();
|
||||||
|
verify(mLockPatternUtils).setVisiblePasswordEnabled(false, UserHandle.myUserId());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security;
|
||||||
|
|
||||||
|
import static android.telephony.TelephonyManager.SIM_STATE_READY;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
import android.telephony.CarrierConfigManager;
|
||||||
|
import android.telephony.SubscriptionInfo;
|
||||||
|
import android.telephony.SubscriptionManager;
|
||||||
|
import android.telephony.TelephonyManager;
|
||||||
|
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class SimLockPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private SubscriptionManager mSubscriptionManager;
|
||||||
|
@Mock
|
||||||
|
private CarrierConfigManager mCarrierManager;
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
@Mock
|
||||||
|
private TelephonyManager mTelephonyManager;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
private SimLockPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||||
|
shadowApplication.setSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE,
|
||||||
|
mSubscriptionManager);
|
||||||
|
shadowApplication.setSystemService(Context.CARRIER_CONFIG_SERVICE, mCarrierManager);
|
||||||
|
shadowApplication.setSystemService(Context.USER_SERVICE, mUserManager);
|
||||||
|
shadowApplication.setSystemService(Context.TELEPHONY_SERVICE, mTelephonyManager);
|
||||||
|
mController = new SimLockPreferenceController(mContext);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_notAdmin_false() {
|
||||||
|
when(mUserManager.isAdminUser()).thenReturn(false);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_simIccNotReady_false() {
|
||||||
|
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_carrierConfigDisabled_false() {
|
||||||
|
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||||
|
setupMockIcc();
|
||||||
|
final PersistableBundle pb = new PersistableBundle();
|
||||||
|
pb.putBoolean(CarrierConfigManager.KEY_HIDE_SIM_LOCK_SETTINGS_BOOL, true);
|
||||||
|
when(mCarrierManager.getConfig()).thenReturn(pb);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAvailable_true() {
|
||||||
|
when(mUserManager.isAdminUser()).thenReturn(true);
|
||||||
|
setupMockIcc();
|
||||||
|
final PersistableBundle pb = new PersistableBundle();
|
||||||
|
when(mCarrierManager.getConfig()).thenReturn(pb);
|
||||||
|
|
||||||
|
assertThat(mController.getAvailabilityStatus())
|
||||||
|
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_simReady_enablePreference() {
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_simNotReady_disablePreference() {
|
||||||
|
setupMockSimReady();
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupMockIcc() {
|
||||||
|
final List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
|
||||||
|
SubscriptionInfo info = mock(SubscriptionInfo.class);
|
||||||
|
subscriptionInfoList.add(info);
|
||||||
|
when(mTelephonyManager.hasIccCard(anyInt()))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList())
|
||||||
|
.thenReturn(subscriptionInfoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupMockSimReady() {
|
||||||
|
final List<SubscriptionInfo> subscriptionInfoList = new ArrayList<>();
|
||||||
|
SubscriptionInfo info = mock(SubscriptionInfo.class);
|
||||||
|
subscriptionInfoList.add(info);
|
||||||
|
when(mTelephonyManager.getSimState(anyInt()))
|
||||||
|
.thenReturn(SIM_STATE_READY);
|
||||||
|
when(mSubscriptionManager.getActiveSubscriptionInfoList())
|
||||||
|
.thenReturn(subscriptionInfoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.security.trustagent;
|
||||||
|
|
||||||
|
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.internal.widget.LockPatternUtils;
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.TestConfig;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
|
public class ManageTrustAgentsPreferenceControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private TrustAgentManager mTrustAgentManager;
|
||||||
|
@Mock
|
||||||
|
private LockPatternUtils mLockPatternUtils;
|
||||||
|
@Mock
|
||||||
|
private PreferenceScreen mScreen;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
private Context mContext;
|
||||||
|
private ManageTrustAgentsPreferenceController mController;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
|
||||||
|
.thenReturn(mLockPatternUtils);
|
||||||
|
when(mFeatureFactory.securityFeatureProvider.getTrustAgentManager())
|
||||||
|
.thenReturn(mTrustAgentManager);
|
||||||
|
mController = new ManageTrustAgentsPreferenceController(mContext);
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(mController.getPreferenceKey());
|
||||||
|
when(mScreen.findPreference(mController.getPreferenceKey()))
|
||||||
|
.thenReturn(mPreference);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isAlwaysAvailable() {
|
||||||
|
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_isNotSecure_shouldDisablePreference() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isFalse();
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.disabled_because_no_backup_security));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_isSecure_noTrustAgent_shouldShowGenericSummary() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
|
||||||
|
.thenReturn(new ArrayList<>());
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getString(R.string.manage_trust_agents_summary));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayPreference_isSecure_hasTrustAgent_shouldShowDetailedSummary() {
|
||||||
|
when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
|
||||||
|
when(mTrustAgentManager.getActiveTrustAgents(mContext, mLockPatternUtils))
|
||||||
|
.thenReturn(Arrays.asList(new TrustAgentManager.TrustAgentComponentInfo()));
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
assertThat(mPreference.isEnabled()).isTrue();
|
||||||
|
assertThat(mPreference.getSummary())
|
||||||
|
.isEqualTo(mContext.getResources().getQuantityString(
|
||||||
|
R.plurals.manage_trust_agents_summary_on, 1, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user