Remove summary provider
- use SummaryProvider to provide the summary of UserSettings - use WifiDisplayPreferenceController to replace the summary loader in WifiDisplaySettings - use ConfigureNotificationPreferernceController to replace the sumary load in ConfigureNotificationSettings Fixes: 141653158 Test: robolectric Change-Id: Id5f5ed645707caa0b25ecae5252174cbf017651c
This commit is contained in:
@@ -2103,12 +2103,6 @@
|
||||
<action android:name="android.settings.CAST_SETTINGS" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.SETTINGS"/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.order" android:value="-6"/>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.device" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.wfd.WifiDisplaySettings" />
|
||||
</activity>
|
||||
@@ -2376,6 +2370,8 @@
|
||||
<meta-data android:name="com.android.settings.order" android:value="-45"/>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.system" />
|
||||
<meta-data android:name="com.android.settings.summary_uri"
|
||||
android:value="content://com.android.settings.dashboard.SummaryProvider/user" />
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.users.UserSettings" />
|
||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||
@@ -2522,14 +2518,6 @@
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="com.android.settings.SHORTCUT" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.android.settings.action.SETTINGS"/>
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.order" android:value="-440"/>
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.apps"/>
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/summary_empty"/>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.notification.ConfigureNotificationSettings" />
|
||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
||||
@@ -2895,9 +2883,8 @@
|
||||
</activity-alias>
|
||||
|
||||
<provider
|
||||
android:name=".backup.BackupSettingsContentProvider"
|
||||
android:authorities="com.android.settings.backup.BackupSettingsContentProvider"
|
||||
android:exported="true">
|
||||
android:name=".dashboard.SummaryProvider"
|
||||
android:authorities="com.android.settings.dashboard.SummaryProvider">
|
||||
</provider>
|
||||
|
||||
<activity android:name=".backup.UserBackupSettingsActivity"
|
||||
@@ -2916,7 +2903,7 @@
|
||||
<meta-data android:name="com.android.settings.category"
|
||||
android:value="com.android.settings.category.ia.system" />
|
||||
<meta-data android:name="com.android.settings.summary_uri"
|
||||
android:value="content://com.android.settings.backup.BackupSettingsContentProvider/summary" />
|
||||
android:value="content://com.android.settings.dashboard.SummaryProvider/backup" />
|
||||
<meta-data android:name="com.android.settings.order" android:value="-60"/>
|
||||
</activity>
|
||||
|
||||
|
@@ -46,6 +46,13 @@
|
||||
android:layout="@layout/preference_category_no_label"
|
||||
android:order="-997"/>
|
||||
|
||||
<Preference
|
||||
android:key="configure_notification_settings"
|
||||
android:title="@string/configure_notification_settings"
|
||||
android:order="-440"
|
||||
android:fragment="com.android.settings.notification.ConfigureNotificationSettings"
|
||||
settings:controller="com.android.settings.notification.ConfigureNotificationPreferenceController"/>
|
||||
|
||||
<!-- Notifications (appears before manage_perms), default apps (appears after) -->
|
||||
<PreferenceCategory
|
||||
android:key="dashboard_tile_placeholder"
|
||||
|
@@ -36,14 +36,6 @@
|
||||
settings:controller="com.android.settings.nfc.NfcPreferenceController"
|
||||
android:order="-7"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:fragment="com.android.settings.nfc.AndroidBeam"
|
||||
android:key="android_beam_settings"
|
||||
android:title="@string/android_beam_settings_title"
|
||||
settings:controller="com.android.settings.nfc.AndroidBeamPreferenceController"
|
||||
android:icon="@drawable/ic_android"
|
||||
android:order="-6"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="nfc_secure_settings"
|
||||
android:title="@string/nfc_secure_settings_title"
|
||||
@@ -52,6 +44,23 @@
|
||||
android:summary="@string/nfc_secure_toggle_summary"
|
||||
android:order="-7"/>
|
||||
|
||||
<Preference
|
||||
android:fragment="com.android.settings.wfd.WifiDisplaySettings"
|
||||
android:key="wifi_display_settings"
|
||||
android:title="@string/wifi_display_settings_title"
|
||||
android:icon="@drawable/ic_cast_24dp"
|
||||
android:order="-6"
|
||||
settings:searchable="false"
|
||||
settings:controller="com.android.settings.wfd.WifiDisplayPreferenceController"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:fragment="com.android.settings.nfc.AndroidBeam"
|
||||
android:key="android_beam_settings"
|
||||
android:title="@string/android_beam_settings_title"
|
||||
settings:controller="com.android.settings.nfc.AndroidBeamPreferenceController"
|
||||
android:icon="@drawable/ic_android"
|
||||
android:order="-5"/>
|
||||
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="connected_device_printing"
|
||||
android:title="@string/print_settings"
|
||||
|
@@ -52,7 +52,6 @@ import androidx.preference.PreferenceManager;
|
||||
import com.android.internal.util.ArrayUtils;
|
||||
import com.android.settings.Settings.WifiSettingsActivity;
|
||||
import com.android.settings.applications.manageapplications.ManageApplications;
|
||||
import com.android.settings.backup.UserBackupSettingsActivity;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
@@ -643,10 +642,6 @@ public class SettingsActivity extends SettingsBaseActivity
|
||||
showDev, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
UserBackupSettingsActivity.class.getName()), true, isAdmin)
|
||||
|| somethingChanged;
|
||||
|
||||
somethingChanged = setTileEnabled(changedList, new ComponentName(packageName,
|
||||
Settings.WifiDisplaySettingsActivity.class.getName()),
|
||||
WifiDisplaySettings.isAvailable(this), isAdmin)
|
||||
|
@@ -54,7 +54,7 @@ public class BackupSettingsHelper {
|
||||
* If there is only one profile, show whether the backup is on or off.
|
||||
* Otherwise, show nothing.
|
||||
*/
|
||||
String getSummary() {
|
||||
public String getSummary() {
|
||||
UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
|
||||
if (userManager.getUserProfiles().size() == 1) {
|
||||
try {
|
||||
|
@@ -37,12 +37,12 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.PreferenceControllerListHelper;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -56,7 +56,7 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
implements SettingsBaseActivity.CategoryListener, Indexable,
|
||||
SummaryLoader.SummaryConsumer, PreferenceGroup.OnExpandButtonClickListener,
|
||||
PreferenceGroup.OnExpandButtonClickListener,
|
||||
BasePreferenceController.UiBlockListener {
|
||||
private static final String TAG = "DashboardFragment";
|
||||
|
||||
@@ -68,7 +68,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
private DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
private DashboardTilePlaceholderPreferenceController mPlaceholderPreferenceController;
|
||||
private boolean mListeningToCategoryChange;
|
||||
private SummaryLoader mSummaryLoader;
|
||||
private List<String> mSuppressInjectedTileKeys;
|
||||
@VisibleForTesting
|
||||
UiBlockerController mBlockerController;
|
||||
@@ -128,7 +127,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
|
||||
if (!keys.isEmpty()) {
|
||||
mBlockerController = new UiBlockerController(keys);
|
||||
mBlockerController.start(()->updatePreferenceVisibility(mPreferenceControllers));
|
||||
mBlockerController.start(() -> updatePreferenceVisibility(mPreferenceControllers));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,10 +168,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
if (category == null) {
|
||||
return;
|
||||
}
|
||||
if (mSummaryLoader != null) {
|
||||
// SummaryLoader can be null when there is no dynamic tiles.
|
||||
mSummaryLoader.setListening(true);
|
||||
}
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof SettingsBaseActivity) {
|
||||
mListeningToCategoryChange = true;
|
||||
@@ -180,19 +175,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySummaryChanged(Tile tile) {
|
||||
final String key = mDashboardFeatureProvider.getDashboardKeyForTile(tile);
|
||||
final Preference pref = getPreferenceScreen().findPreference(key);
|
||||
if (pref == null) {
|
||||
Log.d(getLogTag(), String.format(
|
||||
"Can't find pref by key %s, skipping update summary %s",
|
||||
key, tile.getDescription()));
|
||||
return;
|
||||
}
|
||||
pref.setSummary(tile.getSummary(pref.getContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -220,10 +202,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
if (mSummaryLoader != null) {
|
||||
// SummaryLoader can be null when there is no dynamic tiles.
|
||||
mSummaryLoader.setListening(false);
|
||||
}
|
||||
if (mListeningToCategoryChange) {
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof SettingsBaseActivity) {
|
||||
@@ -413,13 +391,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
// Create a list to track which tiles are to be removed.
|
||||
final List<String> remove = new ArrayList<>(mDashboardTilePrefKeys);
|
||||
|
||||
// There are dashboard tiles, so we need to install SummaryLoader.
|
||||
if (mSummaryLoader != null) {
|
||||
mSummaryLoader.release();
|
||||
}
|
||||
final Context context = getContext();
|
||||
mSummaryLoader = new SummaryLoader(getActivity(), getCategoryKey());
|
||||
mSummaryLoader.setSummaryConsumer(this);
|
||||
// Install dashboard tiles.
|
||||
final boolean forceRoundedIcons = shouldForceRoundedIcon();
|
||||
for (Tile tile : tiles) {
|
||||
@@ -456,7 +427,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
screen.removePreference(preference);
|
||||
}
|
||||
}
|
||||
mSummaryLoader.setListening(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,297 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.Process;
|
||||
import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.List;
|
||||
|
||||
public class SummaryLoader {
|
||||
private static final boolean DEBUG = false;
|
||||
private static final String TAG = "SummaryLoader";
|
||||
|
||||
public static final String SUMMARY_PROVIDER_FACTORY = "SUMMARY_PROVIDER_FACTORY";
|
||||
|
||||
private final Activity mActivity;
|
||||
private final ArrayMap<SummaryProvider, ComponentName> mSummaryProviderMap = new ArrayMap<>();
|
||||
private final ArrayMap<String, CharSequence> mSummaryTextMap = new ArrayMap<>();
|
||||
private final DashboardFeatureProvider mDashboardFeatureProvider;
|
||||
private final String mCategoryKey;
|
||||
|
||||
private final Worker mWorker;
|
||||
private final HandlerThread mWorkerThread;
|
||||
|
||||
private SummaryConsumer mSummaryConsumer;
|
||||
private boolean mListening;
|
||||
private boolean mWorkerListening;
|
||||
private ArraySet<BroadcastReceiver> mReceivers = new ArraySet<>();
|
||||
|
||||
public SummaryLoader(Activity activity, String categoryKey) {
|
||||
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||
.getDashboardFeatureProvider(activity);
|
||||
mCategoryKey = categoryKey;
|
||||
mWorkerThread = new HandlerThread("SummaryLoader", Process.THREAD_PRIORITY_BACKGROUND);
|
||||
mWorkerThread.start();
|
||||
mWorker = new Worker(mWorkerThread.getLooper());
|
||||
mActivity = activity;
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mWorkerThread.quitSafely();
|
||||
// Make sure we aren't listening.
|
||||
setListeningW(false);
|
||||
}
|
||||
|
||||
public void setSummaryConsumer(SummaryConsumer summaryConsumer) {
|
||||
mSummaryConsumer = summaryConsumer;
|
||||
}
|
||||
|
||||
public void setSummary(SummaryProvider provider, final CharSequence summary) {
|
||||
final ComponentName component = mSummaryProviderMap.get(provider);
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
|
||||
final Tile tile = getTileFromCategory(
|
||||
mDashboardFeatureProvider.getTilesForCategory(mCategoryKey), component);
|
||||
|
||||
if (tile == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Can't find tile for " + component);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "setSummary " + tile.getDescription() + " - " + summary);
|
||||
}
|
||||
|
||||
updateSummaryIfNeeded(mActivity.getApplicationContext(), tile, summary);
|
||||
});
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateSummaryIfNeeded(Context context, Tile tile, CharSequence summary) {
|
||||
if (TextUtils.equals(tile.getSummary(context), summary)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Summary doesn't change, skipping summary update for "
|
||||
+ tile.getDescription());
|
||||
}
|
||||
return;
|
||||
}
|
||||
mSummaryTextMap.put(mDashboardFeatureProvider.getDashboardKeyForTile(tile), summary);
|
||||
tile.overrideSummary(summary);
|
||||
if (mSummaryConsumer != null) {
|
||||
mSummaryConsumer.notifySummaryChanged(tile);
|
||||
} else {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "SummaryConsumer is null, skipping summary update for "
|
||||
+ tile.getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Only call from the main thread.
|
||||
*/
|
||||
public void setListening(boolean listening) {
|
||||
if (mListening == listening) {
|
||||
return;
|
||||
}
|
||||
mListening = listening;
|
||||
// Unregister listeners immediately.
|
||||
for (int i = 0; i < mReceivers.size(); i++) {
|
||||
mActivity.unregisterReceiver(mReceivers.valueAt(i));
|
||||
}
|
||||
mReceivers.clear();
|
||||
|
||||
mWorker.removeMessages(Worker.MSG_SET_LISTENING);
|
||||
if (!listening) {
|
||||
// Stop listen
|
||||
mWorker.obtainMessage(Worker.MSG_SET_LISTENING, 0 /* listening */).sendToTarget();
|
||||
} else {
|
||||
// Start listen
|
||||
if (mSummaryProviderMap.isEmpty()) {
|
||||
// Category not initialized yet, init before starting to listen
|
||||
if (!mWorker.hasMessages(Worker.MSG_GET_CATEGORY_TILES_AND_SET_LISTENING)) {
|
||||
mWorker.sendEmptyMessage(Worker.MSG_GET_CATEGORY_TILES_AND_SET_LISTENING);
|
||||
}
|
||||
} else {
|
||||
// Category already initialized, start listening immediately
|
||||
mWorker.obtainMessage(Worker.MSG_SET_LISTENING, 1 /* listening */).sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SummaryProvider getSummaryProvider(Tile tile) {
|
||||
if (!mActivity.getPackageName().equals(tile.getPackageName())) {
|
||||
// Not within Settings, can't load Summary directly.
|
||||
// TODO: Load summary indirectly.
|
||||
return null;
|
||||
}
|
||||
final Bundle metaData = tile.getMetaData();
|
||||
final Intent intent = tile.getIntent();
|
||||
if (metaData == null) {
|
||||
Log.d(TAG, "No metadata specified for " + intent.getComponent());
|
||||
return null;
|
||||
}
|
||||
final String clsName = metaData.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
|
||||
if (clsName == null) {
|
||||
Log.d(TAG, "No fragment specified for " + intent.getComponent());
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
Class<?> cls = Class.forName(clsName);
|
||||
Field field = cls.getField(SUMMARY_PROVIDER_FACTORY);
|
||||
SummaryProviderFactory factory = (SummaryProviderFactory) field.get(null);
|
||||
return factory.createSummaryProvider(mActivity, this);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (DEBUG) Log.d(TAG, "Couldn't find " + clsName, e);
|
||||
} catch (NoSuchFieldException e) {
|
||||
if (DEBUG) Log.d(TAG, "Couldn't find " + SUMMARY_PROVIDER_FACTORY, e);
|
||||
} catch (ClassCastException e) {
|
||||
if (DEBUG) Log.d(TAG, "Couldn't cast " + SUMMARY_PROVIDER_FACTORY, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
if (DEBUG) Log.d(TAG, "Couldn't get " + SUMMARY_PROVIDER_FACTORY, e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a receiver and automatically unregisters it when the activity is stopping.
|
||||
* This ensures that the receivers are unregistered immediately, since most summary loader
|
||||
* operations are asynchronous.
|
||||
*/
|
||||
public void registerReceiver(final BroadcastReceiver receiver, final IntentFilter filter) {
|
||||
mActivity.runOnUiThread(() -> {
|
||||
if (!mListening) {
|
||||
return;
|
||||
}
|
||||
mReceivers.add(receiver);
|
||||
mActivity.registerReceiver(receiver, filter);
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized void setListeningW(boolean listening) {
|
||||
if (mWorkerListening == listening) {
|
||||
return;
|
||||
}
|
||||
mWorkerListening = listening;
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Listening " + listening);
|
||||
}
|
||||
for (SummaryProvider p : mSummaryProviderMap.keySet()) {
|
||||
try {
|
||||
p.setListening(listening);
|
||||
} catch (Exception e) {
|
||||
Log.d(TAG, "Problem in setListening", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized void makeProviderW(Tile tile) {
|
||||
SummaryProvider provider = getSummaryProvider(tile);
|
||||
if (provider != null) {
|
||||
if (DEBUG) Log.d(TAG, "Creating " + tile);
|
||||
mSummaryProviderMap.put(provider, tile.getIntent().getComponent());
|
||||
}
|
||||
}
|
||||
|
||||
private Tile getTileFromCategory(DashboardCategory category, ComponentName component) {
|
||||
if (category == null || category.getTilesCount() == 0) {
|
||||
return null;
|
||||
}
|
||||
final List<Tile> tiles = category.getTiles();
|
||||
final int tileCount = tiles.size();
|
||||
for (int j = 0; j < tileCount; j++) {
|
||||
final Tile tile = tiles.get(j);
|
||||
if (component.equals(tile.getIntent().getComponent())) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public interface SummaryProvider {
|
||||
void setListening(boolean listening);
|
||||
}
|
||||
|
||||
public interface SummaryConsumer {
|
||||
void notifySummaryChanged(Tile tile);
|
||||
}
|
||||
|
||||
public interface SummaryProviderFactory {
|
||||
SummaryProvider createSummaryProvider(Activity activity, SummaryLoader summaryLoader);
|
||||
}
|
||||
|
||||
private class Worker extends Handler {
|
||||
private static final int MSG_GET_CATEGORY_TILES_AND_SET_LISTENING = 1;
|
||||
private static final int MSG_GET_PROVIDER = 2;
|
||||
private static final int MSG_SET_LISTENING = 3;
|
||||
|
||||
public Worker(Looper looper) {
|
||||
super(looper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case MSG_GET_CATEGORY_TILES_AND_SET_LISTENING:
|
||||
final DashboardCategory category =
|
||||
mDashboardFeatureProvider.getTilesForCategory(mCategoryKey);
|
||||
if (category == null || category.getTilesCount() == 0) {
|
||||
return;
|
||||
}
|
||||
final List<Tile> tiles = category.getTiles();
|
||||
for (Tile tile : tiles) {
|
||||
makeProviderW(tile);
|
||||
}
|
||||
setListeningW(true);
|
||||
break;
|
||||
case MSG_GET_PROVIDER:
|
||||
Tile tile = (Tile) msg.obj;
|
||||
makeProviderW(tile);
|
||||
break;
|
||||
case MSG_SET_LISTENING:
|
||||
boolean listening = msg.obj != null && msg.obj.equals(1);
|
||||
setListeningW(listening);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,38 +11,50 @@
|
||||
* 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.
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.backup;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.android.settingslib.drawer.TileUtils.META_DATA_PREFERENCE_SUMMARY;
|
||||
|
||||
/** Provider stores and manages user interaction feedback for homepage contextual cards. */
|
||||
public class BackupSettingsContentProvider extends ContentProvider {
|
||||
private static final String AUTHORITY =
|
||||
"com.android.settings.backup.BackupSettingsContentProvider";
|
||||
private static final String SUMMARY = "summary";
|
||||
private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
static {
|
||||
URI_MATCHER.addURI(AUTHORITY, SUMMARY, 1);
|
||||
}
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.backup.BackupSettingsHelper;
|
||||
|
||||
/** Provide preference summary for injected items. */
|
||||
public class SummaryProvider extends ContentProvider {
|
||||
private static final String BACKUP = "backup";
|
||||
private static final String USER = "user";
|
||||
|
||||
@Override
|
||||
public Bundle call(String method, String uri, Bundle extras) {
|
||||
if (!SUMMARY.equals(method)) {
|
||||
return null;
|
||||
final Bundle bundle = new Bundle();
|
||||
switch (method) {
|
||||
case BACKUP:
|
||||
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
||||
new BackupSettingsHelper(getContext()).getSummary());
|
||||
break;
|
||||
case USER:
|
||||
final Context context = getContext();
|
||||
final UserInfo info = context.getSystemService(UserManager.class).getUserInfo(
|
||||
UserHandle.myUserId());
|
||||
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
||||
context.getString(R.string.users_summary,
|
||||
info.name));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown Uri format: " + uri);
|
||||
}
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(META_DATA_PREFERENCE_SUMMARY,
|
||||
new BackupSettingsHelper(getContext()).getSummary());
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@@ -52,7 +64,8 @@ public class BackupSettingsContentProvider extends ContentProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
||||
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
|
||||
String sortOrder) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class ConfigureNotificationPreferenceController extends BasePreferenceController {
|
||||
|
||||
private NotificationBackend mBackend;
|
||||
|
||||
public ConfigureNotificationPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mBackend = new NotificationBackend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final int blockedAppCount = mBackend.getBlockedAppCount();
|
||||
if (blockedAppCount == 0) {
|
||||
return mContext.getText(R.string.app_notification_listing_summary_zero);
|
||||
}
|
||||
return mContext.getResources().getQuantityString(
|
||||
R.plurals.app_notification_listing_summary_others,
|
||||
blockedAppCount, blockedAppCount);
|
||||
}
|
||||
}
|
@@ -40,7 +40,6 @@ import com.android.settings.R;
|
||||
import com.android.settings.RingtonePreference;
|
||||
import com.android.settings.core.OnActivityResultListener;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
@@ -162,54 +161,6 @@ public class ConfigureNotificationSettings extends DashboardFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For summary
|
||||
*/
|
||||
static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private NotificationBackend mBackend;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mBackend = new NotificationBackend();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected void setBackend(NotificationBackend backend) {
|
||||
mBackend = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (!listening) {
|
||||
return;
|
||||
}
|
||||
int blockedAppCount = mBackend.getBlockedAppCount();
|
||||
if (blockedAppCount == 0) {
|
||||
mSummaryLoader.setSummary(this,
|
||||
mContext.getText(R.string.app_notification_listing_summary_zero));
|
||||
} else {
|
||||
mSummaryLoader.setSummary(this,
|
||||
mContext.getResources().getQuantityString(
|
||||
R.plurals.app_notification_listing_summary_others,
|
||||
blockedAppCount, blockedAppCount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
|
||||
new SummaryLoader.SummaryProviderFactory() {
|
||||
@Override
|
||||
public SummaryLoader.SummaryProvider createSummaryProvider(Activity activity,
|
||||
SummaryLoader summaryLoader) {
|
||||
return new ConfigureNotificationSettings.SummaryProvider(
|
||||
activity, summaryLoader);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
|
@@ -63,7 +63,6 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.password.ChooseLockGeneric;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.SwitchBar;
|
||||
@@ -1195,30 +1194,6 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
}
|
||||
}
|
||||
|
||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
UserInfo info = mContext.getSystemService(UserManager.class).getUserInfo(
|
||||
UserHandle.myUserId());
|
||||
mSummaryLoader.setSummary(this, mContext.getString(R.string.users_summary,
|
||||
info.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
|
||||
(activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.user_settings) {
|
||||
|
||||
|
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.wfd;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.MediaRouter;
|
||||
import android.media.MediaRouter.RouteInfo;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
public class WifiDisplayPreferenceController extends BasePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private final MediaRouter mRouter;
|
||||
private Preference mPreference;
|
||||
private final MediaRouter.Callback mRouterCallback = new MediaRouter.SimpleCallback() {
|
||||
@Override
|
||||
public void onRouteSelected(MediaRouter router, int type, RouteInfo info) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteAdded(MediaRouter router, RouteInfo info) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteRemoved(MediaRouter router, RouteInfo info) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteChanged(MediaRouter router, RouteInfo info) {
|
||||
refreshSummary(mPreference);
|
||||
}
|
||||
};
|
||||
|
||||
public WifiDisplayPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mRouter = context.getSystemService(MediaRouter.class);
|
||||
mRouter.setRouterGroupId(MediaRouter.MIRRORING_GROUP_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return WifiDisplaySettings.isAvailable(mContext) ? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
CharSequence summary = mContext.getString(R.string.disconnected);
|
||||
|
||||
final int routeCount = mRouter.getRouteCount();
|
||||
for (int i = 0; i < routeCount; i++) {
|
||||
final MediaRouter.RouteInfo route = mRouter.getRouteAt(i);
|
||||
if (route.matchesTypes(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)
|
||||
&& route.isSelected() && !route.isConnecting()) {
|
||||
summary = mContext.getString(R.string.wifi_display_status_connected);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return summary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mRouter.addCallback(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY, mRouterCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mRouter.removeCallback(mRouterCallback);
|
||||
}
|
||||
}
|
@@ -37,7 +37,6 @@ import android.net.wifi.p2p.WifiP2pManager.Channel;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.util.Slog;
|
||||
import android.util.TypedValue;
|
||||
@@ -64,15 +63,11 @@ import androidx.preference.SwitchPreference;
|
||||
import com.android.internal.app.MediaRouteDialogPresenter;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* The Settings screen for WifiDisplay configuration and connection management.
|
||||
*
|
||||
@@ -767,74 +762,6 @@ public final class WifiDisplaySettings extends SettingsPreferenceFragment implem
|
||||
}
|
||||
}
|
||||
|
||||
private static class SummaryProvider implements SummaryLoader.SummaryProvider {
|
||||
|
||||
private final Context mContext;
|
||||
private final SummaryLoader mSummaryLoader;
|
||||
private final MediaRouter mRouter;
|
||||
private final MediaRouter.Callback mRouterCallback = new MediaRouter.SimpleCallback() {
|
||||
@Override
|
||||
public void onRouteSelected(MediaRouter router, int type, RouteInfo info) {
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteUnselected(MediaRouter router, int type, RouteInfo info) {
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteAdded(MediaRouter router, RouteInfo info) {
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteRemoved(MediaRouter router, RouteInfo info) {
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRouteChanged(MediaRouter router, RouteInfo info) {
|
||||
updateSummary();
|
||||
}
|
||||
};
|
||||
|
||||
public SummaryProvider(Context context, SummaryLoader summaryLoader) {
|
||||
mContext = context;
|
||||
mSummaryLoader = summaryLoader;
|
||||
mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);
|
||||
mRouter.setRouterGroupId(MediaRouter.MIRRORING_GROUP_ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setListening(boolean listening) {
|
||||
if (listening) {
|
||||
mRouter.addCallback(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY, mRouterCallback);
|
||||
updateSummary();
|
||||
} else {
|
||||
mRouter.removeCallback(mRouterCallback);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSummary() {
|
||||
String summary = mContext.getString(R.string.disconnected);
|
||||
|
||||
final int routeCount = mRouter.getRouteCount();
|
||||
for (int i = 0; i < routeCount; i++) {
|
||||
final MediaRouter.RouteInfo route = mRouter.getRouteAt(i);
|
||||
if (route.matchesTypes(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)
|
||||
&& route.isSelected() && !route.isConnecting()) {
|
||||
summary = mContext.getString(R.string.wifi_display_status_connected);
|
||||
break;
|
||||
}
|
||||
}
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY
|
||||
= (activity, summaryLoader) -> new SummaryProvider(activity, summaryLoader);
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.wifi_display_settings);
|
||||
}
|
||||
|
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SummaryLoaderTest {
|
||||
|
||||
private static final String SUMMARY_1 = "summary1";
|
||||
private static final String SUMMARY_2 = "summary2";
|
||||
|
||||
private Context mContext;
|
||||
private SummaryLoader mSummaryLoader;
|
||||
private boolean mCallbackInvoked;
|
||||
private Tile mTile;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@Before
|
||||
public void SetUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
final ActivityInfo activityInfo = new ActivityInfo();
|
||||
activityInfo.packageName = "pkg";
|
||||
activityInfo.name = "class";
|
||||
mTile = new Tile(activityInfo, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mTile.overrideSummary(SUMMARY_1);
|
||||
mCallbackInvoked = false;
|
||||
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).get();
|
||||
|
||||
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mSummaryLoader.setSummaryConsumer(tile -> mCallbackInvoked = true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newInstance_shouldNotLoadCategory() {
|
||||
verifyZeroInteractions(mFeatureFactory.dashboardFeatureProvider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSummaryIfNeeded_SummaryIdentical_NoCallback() {
|
||||
mSummaryLoader.updateSummaryIfNeeded(mContext, mTile, SUMMARY_1);
|
||||
|
||||
assertThat(mCallbackInvoked).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSummaryIfNeeded_SummaryChanged_HasCallback() {
|
||||
mSummaryLoader.updateSummaryIfNeeded(mContext, mTile, SUMMARY_2);
|
||||
|
||||
assertThat(mCallbackInvoked).isTrue();
|
||||
}
|
||||
}
|
@@ -19,9 +19,7 @@ package com.android.settings.datausage;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyObject;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.endsWith;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -36,7 +34,6 @@ import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.shadow.ShadowDashboardFragment;
|
||||
import com.android.settings.testutils.shadow.ShadowDataUsageUtils;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
@@ -65,8 +62,6 @@ import org.robolectric.shadows.ShadowTelephonyManager;
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class DataUsageSummaryTest {
|
||||
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
@Mock
|
||||
private NetworkPolicyManager mNetworkPolicyManager;
|
||||
@Mock
|
||||
|
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.testutils.shadow.ShadowNotificationBackend;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowNotificationBackend.class)
|
||||
public class ConfigureNotificationPreferenceControllerTest {
|
||||
|
||||
private ConfigureNotificationPreferenceController mController;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mController = new ConfigureNotificationPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_noBlockedApps() {
|
||||
ShadowNotificationBackend.setBlockedAppCount(0);
|
||||
|
||||
assertThat(mController.getSummary().toString()).contains("On");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_someBlockedApps() {
|
||||
ShadowNotificationBackend.setBlockedAppCount(5);
|
||||
|
||||
assertThat(mController.getSummary().toString()).contains("Off");
|
||||
assertThat(mController.getSummary().toString()).contains("5");
|
||||
}
|
||||
}
|
@@ -1,85 +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.notification;
|
||||
|
||||
import static com.android.settings.notification.ConfigureNotificationSettings.SUMMARY_PROVIDER_FACTORY;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.notification.ConfigureNotificationSettings.SummaryProvider;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.robolectric.Robolectric;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class ConfigureNotificationSettingsTest {
|
||||
|
||||
private Activity mActivity;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mActivity = spy(Robolectric.buildActivity(Activity.class).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_noneBlocked() {
|
||||
SummaryLoader loader = mock(SummaryLoader.class);
|
||||
NotificationBackend backend = mock(NotificationBackend.class);
|
||||
when(backend.getBlockedAppCount()).thenReturn(0);
|
||||
SummaryProvider provider =
|
||||
(SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
|
||||
provider.setBackend(backend);
|
||||
|
||||
provider.setListening(true);
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(loader).setSummary(any(), captor.capture());
|
||||
|
||||
assertThat(captor.getValue().toString()).contains("On");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_someBlocked() {
|
||||
SummaryLoader loader = mock(SummaryLoader.class);
|
||||
NotificationBackend backend = mock(NotificationBackend.class);
|
||||
when(backend.getBlockedAppCount()).thenReturn(5);
|
||||
SummaryProvider provider =
|
||||
(SummaryProvider) SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, loader);
|
||||
provider.setBackend(backend);
|
||||
|
||||
provider.setListening(true);
|
||||
|
||||
ArgumentCaptor<CharSequence> captor = ArgumentCaptor.forClass(CharSequence.class);
|
||||
verify(loader).setSummary(any(), captor.capture());
|
||||
|
||||
assertThat(captor.getValue().toString()).contains("Off");
|
||||
assertThat(captor.getValue().toString()).contains("5");
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.testutils.shadow;
|
||||
|
||||
import com.android.settings.notification.NotificationBackend;
|
||||
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
@Implements(NotificationBackend.class)
|
||||
public class ShadowNotificationBackend {
|
||||
|
||||
private static int sBlockAppCount;
|
||||
|
||||
@Implementation
|
||||
protected int getBlockedAppCount() {
|
||||
return sBlockAppCount;
|
||||
}
|
||||
|
||||
public static void setBlockedAppCount(int blockAppCount) {
|
||||
sBlockAppCount = blockAppCount;
|
||||
}
|
||||
}
|
@@ -32,7 +32,6 @@ import static org.mockito.Mockito.when;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
@@ -49,8 +48,6 @@ import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
@@ -86,14 +83,11 @@ public class UserSettingsTest {
|
||||
private UserPreference mMePreference;
|
||||
@Mock
|
||||
private UserManager mUserManager;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
|
||||
private FragmentActivity mActivity;
|
||||
private Context mContext;
|
||||
private UserSettings mFragment;
|
||||
private UserCapabilities mUserCapabilities;
|
||||
private SummaryLoader.SummaryProvider mSummaryProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -123,9 +117,6 @@ public class UserSettingsTest {
|
||||
final SharedPreferences prefs = mock(SharedPreferences .class);
|
||||
when(mMockPreferenceManager.getSharedPreferences()).thenReturn(prefs);
|
||||
when(mMockPreferenceManager.getContext()).thenReturn(mContext);
|
||||
|
||||
mSummaryProvider =
|
||||
UserSettings.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(mActivity, mSummaryLoader);
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -134,19 +125,6 @@ public class UserSettingsTest {
|
||||
Settings.Global.DEVICE_PROVISIONED, mProvisioned);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setListening_shouldSetSummaryWithUserName() {
|
||||
final String name = "John";
|
||||
final UserInfo userInfo = new UserInfo();
|
||||
userInfo.name = name;
|
||||
when(mUserManager.getUserInfo(anyInt())).thenReturn(userInfo);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mSummaryLoader)
|
||||
.setSummary(mSummaryProvider, mActivity.getString(R.string.users_summary, name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssignDefaultPhoto_ContextNull_ReturnFalseAndNotCrash() {
|
||||
// Should not crash here
|
||||
|
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
|
||||
package com.android.settings.wfd;
|
||||
|
||||
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.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.media.MediaRouter;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class WifiDisplayPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private WifiDisplayPreferenceController mWifiDisplayPreferenceController;
|
||||
@Mock
|
||||
private MediaRouter mMediaRouter;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getSystemService(Context.MEDIA_ROUTER_SERVICE)).thenReturn(mMediaRouter);
|
||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
|
||||
mWifiDisplayPreferenceController = new WifiDisplayPreferenceController(mContext, "key");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_disconnected_shouldProvideDisconnectedSummary() {
|
||||
assertThat(mWifiDisplayPreferenceController.getSummary().toString()).contains(
|
||||
mContext.getString(R.string.disconnected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSummary_connected_shouldProvideConnectedSummary() {
|
||||
final MediaRouter.RouteInfo route = mock(MediaRouter.RouteInfo.class);
|
||||
when(mMediaRouter.getRouteCount()).thenReturn(1);
|
||||
when(mMediaRouter.getRouteAt(0)).thenReturn(route);
|
||||
when(route.matchesTypes(anyInt())).thenReturn(true);
|
||||
when(route.isSelected()).thenReturn(true);
|
||||
when(route.isConnecting()).thenReturn(false);
|
||||
|
||||
assertThat(mWifiDisplayPreferenceController.getSummary().toString()).contains(
|
||||
mContext.getString(R.string.wifi_display_status_connected));
|
||||
}
|
||||
}
|
@@ -19,8 +19,6 @@ package com.android.settings.wfd;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -30,9 +28,6 @@ import android.hardware.display.DisplayManager;
|
||||
import android.media.MediaRouter;
|
||||
import android.net.wifi.p2p.WifiP2pManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -46,45 +41,16 @@ public class WifiDisplaySettingsTest {
|
||||
@Mock
|
||||
private Activity mActivity;
|
||||
@Mock
|
||||
private SummaryLoader mSummaryLoader;
|
||||
@Mock
|
||||
private MediaRouter mMediaRouter;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
|
||||
private SummaryLoader.SummaryProvider mSummaryProvider;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
when(mActivity.getSystemService(Context.MEDIA_ROUTER_SERVICE)).thenReturn(mMediaRouter);
|
||||
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
|
||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_WIFI_DIRECT)).thenReturn(true);
|
||||
|
||||
mSummaryProvider = WifiDisplaySettings.SUMMARY_PROVIDER_FACTORY
|
||||
.createSummaryProvider(mActivity, mSummaryLoader);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenToSummary_disconnected_shouldProvideDisconnectedSummary() {
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mActivity).getString(R.string.disconnected);
|
||||
verify(mActivity, never()).getString(R.string.wifi_display_status_connected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void listenToSummary_connected_shouldProvideConnectedSummary() {
|
||||
final MediaRouter.RouteInfo route = mock(MediaRouter.RouteInfo.class);
|
||||
when(mMediaRouter.getRouteCount()).thenReturn(1);
|
||||
when(mMediaRouter.getRouteAt(0)).thenReturn(route);
|
||||
when(route.matchesTypes(MediaRouter.ROUTE_TYPE_REMOTE_DISPLAY)).thenReturn(true);
|
||||
when(route.isSelected()).thenReturn(true);
|
||||
when(route.isConnecting()).thenReturn(false);
|
||||
|
||||
mSummaryProvider.setListening(true);
|
||||
|
||||
verify(mActivity).getString(R.string.wifi_display_status_connected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user