Merge "Fix failed test cases"
diff --git a/res/xml/zen_mode_settings.xml b/res/xml/zen_mode_settings.xml
index 240c4c5..b8af650 100644
--- a/res/xml/zen_mode_settings.xml
+++ b/res/xml/zen_mode_settings.xml
@@ -56,9 +56,10 @@
android:key="zen_mode_settings_category_schedule"
android:title="@string/zen_category_schedule">
<!-- DND duration settings -->
- <Preference
+ <com.android.settings.notification.ZenDurationDialogPreference
android:key="zen_mode_duration_settings"
- android:title="@string/zen_mode_duration_settings_title" />
+ android:title="@string/zen_mode_duration_settings_title"
+ android:widgetLayout="@null"/>
<!-- Automatic rules -->
<Preference
diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java
index 0df0e6f..d268eb6 100644
--- a/src/com/android/settings/SettingsActivity.java
+++ b/src/com/android/settings/SettingsActivity.java
@@ -723,7 +723,8 @@
for (DashboardCategory category : categories) {
final int tileCount = category.getTilesCount();
for (int i = 0; i < tileCount; i++) {
- final ComponentName component = category.getTile(i).intent.getComponent();
+ final ComponentName component = category.getTile(i)
+ .getIntent().getComponent();
final String name = component.getClassName();
final boolean isEnabledForRestricted = ArrayUtils.contains(
SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
diff --git a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
index 14d2fd3..f98aee1 100644
--- a/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
+++ b/src/com/android/settings/accounts/AccountDetailDashboardFragment.java
@@ -22,6 +22,9 @@
import android.os.UserHandle;
import android.os.UserManager;
+import androidx.annotation.VisibleForTesting;
+import androidx.preference.PreferenceScreen;
+
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.Utils;
@@ -33,9 +36,6 @@
import java.util.ArrayList;
import java.util.List;
-import androidx.annotation.VisibleForTesting;
-import androidx.preference.PreferenceScreen;
-
public class AccountDetailDashboardFragment extends DashboardFragment {
private static final String TAG = "AccountDetailDashboard";
@@ -131,8 +131,8 @@
return false;
}
final boolean display = mAccountType.equals(metadata.getString(METADATA_IA_ACCOUNT));
- if (display && tile.intent != null) {
- tile.intent.putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
+ if (display) {
+ tile.getIntent().putExtra(EXTRA_ACCOUNT_NAME, mAccount.name);
}
return display;
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
index dece0cc..84cab40 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceUpdater.java
@@ -128,9 +128,6 @@
}
@Override
- public void onScanningStateChanged(boolean started) {}
-
- @Override
public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
update(cachedDevice);
}
@@ -149,17 +146,6 @@
}
@Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {}
-
- @Override
- public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
- }
-
- @Override
- public void onAudioModeChanged() {
- }
-
- @Override
public void onProfileConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state,
int bluetoothProfile) {
if (DBG) {
diff --git a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
index 03fffa4..d577b0a 100644
--- a/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
+++ b/src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java
@@ -59,30 +59,6 @@
}
@Override
- public void onScanningStateChanged(boolean started) {
- }
-
- @Override
- public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
- }
-
- @Override
- public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
- }
-
- @Override
- public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
- }
-
- @Override
- public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
- }
-
- @Override
- public void onAudioModeChanged() {
- }
-
- @Override
public void register(boolean listening) {
if (mBluetoothAdapter == null) {
return;
diff --git a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
index 7c4224e..46d649a 100644
--- a/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
+++ b/src/com/android/settings/bluetooth/DeviceListPreferenceFragment.java
@@ -244,9 +244,6 @@
}
}
- @Override
- public void onBluetoothStateChanged(int bluetoothState) {}
-
/**
* Add bluetooth device preferences to {@code preferenceGroup} which satisfy the {@code filter}
*
@@ -270,14 +267,6 @@
removeCachedPrefs(preferenceGroup);
}
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }
-
- @Override
- public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) { }
-
- @Override
- public void onAudioModeChanged() { }
-
/**
* Return the key of the {@link PreferenceGroup} that contains the bluetooth devices
*/
diff --git a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
index 5959414..183ed3f 100644
--- a/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
+++ b/src/com/android/settings/connecteddevice/AvailableMediaDeviceGroupController.java
@@ -28,7 +28,6 @@
import com.android.settings.core.BasePreferenceController;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.bluetooth.BluetoothCallback;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
@@ -132,41 +131,6 @@
}
@Override
- public void onBluetoothStateChanged(int bluetoothState) {
- // do nothing
- }
-
- @Override
- public void onScanningStateChanged(boolean started) {
- // do nothing
- }
-
- @Override
- public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
- // do nothing
- }
-
- @Override
- public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
- // do nothing
- }
-
- @Override
- public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
- // do nothing
- }
-
- @Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
- // do nothing
- }
-
- @Override
- public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
- // do nothing
- }
-
- @Override
public void onAudioModeChanged() {
updateTitle();
}
diff --git a/src/com/android/settings/dashboard/CategoryManager.java b/src/com/android/settings/dashboard/CategoryManager.java
index baabe28..21324b2 100644
--- a/src/com/android/settings/dashboard/CategoryManager.java
+++ b/src/com/android/settings/dashboard/CategoryManager.java
@@ -98,7 +98,7 @@
DashboardCategory category = mCategories.get(i);
for (int j = 0; j < category.getTilesCount(); j++) {
Tile tile = category.getTile(j);
- if (tileBlacklist.contains(tile.intent.getComponent())) {
+ if (tileBlacklist.contains(tile.getIntent().getComponent())) {
category.removeTile(j--);
}
}
@@ -205,10 +205,7 @@
final Set<ComponentName> components = new ArraySet<>();
for (int i = count - 1; i >= 0; i--) {
final Tile tile = category.getTile(i);
- if (tile.intent == null) {
- continue;
- }
- final ComponentName tileComponent = tile.intent.getComponent();
+ final ComponentName tileComponent = tile.getIntent().getComponent();
if (components.contains(tileComponent)) {
category.removeTile(i);
} else {
diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java
index fc1a129..d3afd3f 100644
--- a/src/com/android/settings/dashboard/DashboardAdapter.java
+++ b/src/com/android/settings/dashboard/DashboardAdapter.java
@@ -64,7 +64,7 @@
@VisibleForTesting
static final String STATE_CONDITION_EXPANDED = "condition_expanded";
-
+ static final String META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB = "com.android.settings.bg.argb";
private final IconCache mCache;
private final Context mContext;
private final MetricsFeatureProvider mMetricsFeatureProvider;
@@ -320,20 +320,30 @@
if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
&& !(icon instanceof RoundedHomepageIcon)) {
icon = new RoundedHomepageIcon(mContext, icon);
+ final Bundle metaData = tile.getMetaData();
try {
- final Bundle metaData = tile.getMetaData();
if (metaData != null) {
- final int colorRes = metaData.getInt(
- TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
- if (colorRes != 0) {
- final int bgColor = mContext.getPackageManager()
- .getResourcesForApplication(tileIcon.getResPackage())
- .getColor(colorRes, null /* theme */);
+ // Load from bg.argb first
+ int bgColor = metaData.getInt(META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
+ 0 /* default */);
+ // Not found, load from bg.hint
+ if (bgColor == 0) {
+ final int colorRes = metaData.getInt(
+ TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
+ 0 /* default */);
+ if (colorRes != 0) {
+ bgColor = mContext.getPackageManager()
+ .getResourcesForApplication(tileIcon.getResPackage())
+ .getColor(colorRes, null /* theme */);
+ }
+ }
+ // If found anything, use it.
+ if (bgColor != 0) {
((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
}
}
} catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Failed to set background color for " + tile.intent.getPackage());
+ Log.e(TAG, "Failed to set background color for " + tile.getPackageName());
}
mCache.updateIcon(tileIcon, icon);
}
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 42bc777..49c7bbb 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -117,14 +117,14 @@
@Override
public String getDashboardKeyForTile(Tile tile) {
- if (tile == null || tile.intent == null) {
+ if (tile == null) {
return null;
}
if (!TextUtils.isEmpty(tile.key)) {
return tile.key;
}
final StringBuilder sb = new StringBuilder(DASHBOARD_TILE_PREF_KEY_PREFIX);
- final ComponentName component = tile.intent.getComponent();
+ final ComponentName component = tile.getIntent().getComponent();
sb.append(component.getClassName());
return sb.toString();
}
@@ -157,8 +157,8 @@
}
if (!TextUtils.isEmpty(clsName)) {
pref.setFragment(clsName);
- } else if (tile.intent != null) {
- final Intent intent = new Intent(tile.intent);
+ } else {
+ final Intent intent = new Intent(tile.getIntent());
intent.putExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY,
sourceMetricsCategory);
if (action != null) {
@@ -178,11 +178,8 @@
order = -tile.priority;
}
if (order != null) {
- boolean shouldSkipBaseOrderOffset = false;
- if (tile.intent != null) {
- shouldSkipBaseOrderOffset = TextUtils.equals(
- skipOffsetPackageName, tile.intent.getComponent().getPackageName());
- }
+ boolean shouldSkipBaseOrderOffset = TextUtils.equals(
+ skipOffsetPackageName, tile.getIntent().getComponent().getPackageName());
if (shouldSkipBaseOrderOffset || baseOrder == Preference.DEFAULT_ORDER) {
pref.setOrder(order);
} else {
@@ -204,11 +201,7 @@
mContext.startActivity(intent);
return;
}
-
- if (tile.intent == null) {
- return;
- }
- final Intent intent = new Intent(tile.intent)
+ final Intent intent = new Intent(tile.getIntent())
.putExtra(VisibilityLoggerMixin.EXTRA_SOURCE_METRICS_CATEGORY,
MetricsEvent.DASHBOARD_SUMMARY)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
@@ -244,14 +237,12 @@
} else if (tile.getMetaData() != null
&& tile.getMetaData().containsKey(META_DATA_PREFERENCE_ICON_URI)) {
ThreadUtils.postOnBackgroundThread(() -> {
+ final Intent intent = tile.getIntent();
String packageName = null;
- if (tile.intent != null) {
- Intent intent = tile.intent;
- if (!TextUtils.isEmpty(intent.getPackage())) {
- packageName = intent.getPackage();
- } else if (intent.getComponent() != null) {
- packageName = intent.getComponent().getPackageName();
- }
+ if (!TextUtils.isEmpty(intent.getPackage())) {
+ packageName = intent.getPackage();
+ } else if (intent.getComponent() != null) {
+ packageName = intent.getComponent().getPackageName();
}
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String uri = tile.getMetaData().getString(META_DATA_PREFERENCE_ICON_URI);
diff --git a/src/com/android/settings/dashboard/SummaryLoader.java b/src/com/android/settings/dashboard/SummaryLoader.java
index d8694f2..199331d 100644
--- a/src/com/android/settings/dashboard/SummaryLoader.java
+++ b/src/com/android/settings/dashboard/SummaryLoader.java
@@ -18,6 +18,7 @@
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
+import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
@@ -155,19 +156,20 @@
}
private SummaryProvider getSummaryProvider(Tile tile) {
- if (!mActivity.getPackageName().equals(tile.intent.getComponent().getPackageName())) {
+ 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) {
- if (DEBUG) Log.d(TAG, "No metadata specified for " + tile.intent.getComponent());
+ Log.d(TAG, "No metadata specified for " + intent.getComponent());
return null;
}
- String clsName = metaData.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
+ final String clsName = metaData.getString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS);
if (clsName == null) {
- if (DEBUG) Log.d(TAG, "No fragment specified for " + tile.intent.getComponent());
+ Log.d(TAG, "No fragment specified for " + intent.getComponent());
return null;
}
try {
@@ -193,15 +195,12 @@
* operations are asynchronous.
*/
public void registerReceiver(final BroadcastReceiver receiver, final IntentFilter filter) {
- mActivity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- if (!mListening) {
- return;
- }
- mReceivers.add(receiver);
- mActivity.registerReceiver(receiver, filter);
+ mActivity.runOnUiThread(() -> {
+ if (!mListening) {
+ return;
}
+ mReceivers.add(receiver);
+ mActivity.registerReceiver(receiver, filter);
});
}
@@ -242,7 +241,7 @@
SummaryProvider provider = getSummaryProvider(tile);
if (provider != null) {
if (DEBUG) Log.d(TAG, "Creating " + tile);
- mSummaryProviderMap.put(provider, tile.intent.getComponent());
+ mSummaryProviderMap.put(provider, tile.getIntent().getComponent());
}
}
@@ -254,7 +253,7 @@
final int tileCount = tiles.size();
for (int j = 0; j < tileCount; j++) {
final Tile tile = tiles.get(j);
- if (component.equals(tile.intent.getComponent())) {
+ if (component.equals(tile.getIntent().getComponent())) {
return tile;
}
}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index e56c58b..b49f401 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -71,8 +71,9 @@
public void onClick(DialogInterface dialog, int which) {
UserHandle user = mSelectedTile.userHandle.get(which);
// Show menu on top level items.
- mSelectedTile.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
- getActivity().startActivityAsUser(mSelectedTile.intent, user);
+ final Intent intent = mSelectedTile.getIntent();
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ getActivity().startActivityAsUser(intent, user);
}
public static void updateUserHandlesIfNeeded(Context context, Tile tile) {
diff --git a/src/com/android/settings/notification/ZenDurationDialogPreference.java b/src/com/android/settings/notification/ZenDurationDialogPreference.java
new file mode 100644
index 0000000..a161d6e
--- /dev/null
+++ b/src/com/android/settings/notification/ZenDurationDialogPreference.java
@@ -0,0 +1,52 @@
+/*
+ * 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.notification;
+
+import android.content.Context;
+import android.content.DialogInterface;
+import android.util.AttributeSet;
+
+import com.android.settingslib.CustomDialogPreferenceCompat;
+import com.android.settingslib.notification.ZenDurationDialog;
+
+import androidx.appcompat.app.AlertDialog;
+
+public class ZenDurationDialogPreference extends CustomDialogPreferenceCompat {
+
+ public ZenDurationDialogPreference(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public ZenDurationDialogPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public ZenDurationDialogPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+
+ @Override
+ protected void onPrepareDialogBuilder(AlertDialog.Builder builder,
+ DialogInterface.OnClickListener listener) {
+ super.onPrepareDialogBuilder(builder, listener);
+
+ ZenDurationDialog zenDialog = new ZenDurationDialog(getContext());
+ zenDialog.setupDialog(builder);
+ }
+}
diff --git a/src/com/android/settings/notification/ZenModeDurationPreferenceController.java b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java
index 0f884dd..3972bb1 100644
--- a/src/com/android/settings/notification/ZenModeDurationPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeDurationPreferenceController.java
@@ -22,21 +22,13 @@
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
-import androidx.fragment.app.FragmentManager;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
public class ZenModeDurationPreferenceController extends AbstractZenModePreferenceController
- implements PreferenceControllerMixin, Preference.OnPreferenceClickListener {
+ implements PreferenceControllerMixin {
- private static final String TAG = "ZenModeDurationDialog";
protected static final String KEY = "zen_mode_duration_settings";
- private FragmentManager mFragment;
- public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle, FragmentManager
- fragment) {
+ public ZenModeDurationPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mFragment = fragment;
}
@Override
@@ -50,16 +42,8 @@
}
@Override
- public void displayPreference(PreferenceScreen screen) {
- super.displayPreference(screen);
- screen.findPreference(KEY).setOnPreferenceClickListener(this);
- }
-
- @Override
- public void updateState(Preference preference) {
- super.updateState(preference);
-
- String summary = "";
+ public CharSequence getSummary() {
+ String summary;
int zenDuration = getZenDuration();
if (zenDuration < 0) {
summary = mContext.getString(R.string.zen_mode_duration_summary_always_prompt);
@@ -76,12 +60,6 @@
}
}
- preference.setSummary(summary);
+ return summary;
}
-
- @Override
- public boolean onPreferenceClick(Preference preference) {
- new SettingsZenDurationDialog().show(mFragment, TAG);
- return true;
- }
-}
\ No newline at end of file
+}
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index ce8fe4d..f2ebd2b 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -86,8 +86,7 @@
controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeDurationPreferenceController(context, lifecycle,
- fragmentManager));
+ controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context));
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
diff --git a/src/com/android/settings/sound/AudioSwitchPreferenceController.java b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
index dcbed15..d5e3aff 100644
--- a/src/com/android/settings/sound/AudioSwitchPreferenceController.java
+++ b/src/com/android/settings/sound/AudioSwitchPreferenceController.java
@@ -184,14 +184,6 @@
unregister();
}
- /**
- * Only concerned about whether the local adapter is connected to any profile of any device and
- * are not really concerned about which profile.
- */
- @Override
- public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) {
- }
-
@Override
public void onActiveDeviceChanged(CachedBluetoothDevice activeDevice, int bluetoothProfile) {
updateState(mPreference);
@@ -208,17 +200,6 @@
updateState(mPreference);
}
- @Override
- public void onBluetoothStateChanged(int bluetoothState) {
- }
-
- /**
- * The local Bluetooth adapter has started the remote device discovery process.
- */
- @Override
- public void onScanningStateChanged(boolean started) {
- }
-
/**
* Indicates a change in the bond state of a remote
* device. For example, if a device is bonded (paired).
@@ -228,14 +209,6 @@
updateState(mPreference);
}
- @Override
- public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
- }
-
- @Override
- public void onDeviceBondStateChanged(CachedBluetoothDevice cachedDevice, int bondState) {
- }
-
public void setCallback(AudioSwitchCallback callback) {
mAudioSwitchPreferenceCallback = callback;
}
diff --git a/src/com/android/settings/users/EditUserInfoController.java b/src/com/android/settings/users/EditUserInfoController.java
index 6045516..2035f66 100644
--- a/src/com/android/settings/users/EditUserInfoController.java
+++ b/src/com/android/settings/users/EditUserInfoController.java
@@ -41,6 +41,7 @@
import java.io.File;
import androidx.appcompat.app.AlertDialog;
+import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
/**
@@ -103,9 +104,8 @@
public void onActivityResult(int requestCode, int resultCode, Intent data) {
mWaitingForActivityResult = false;
- if (mEditUserInfoDialog != null && mEditUserInfoDialog.isShowing()
- && mEditUserPhotoController.onActivityResult(requestCode, resultCode, data)) {
- return;
+ if (mEditUserInfoDialog != null) {
+ mEditUserPhotoController.onActivityResult(requestCode, resultCode, data);
}
}
@@ -115,7 +115,7 @@
Activity activity = fragment.getActivity();
mUser = user;
if (mUserManager == null) {
- mUserManager = UserManager.get(activity);
+ mUserManager = activity.getSystemService(UserManager.class);
}
LayoutInflater inflater = activity.getLayoutInflater();
View content = inflater.inflate(R.layout.edit_user_info_dialog_content, null);
@@ -136,8 +136,7 @@
}
}
userPhotoView.setImageDrawable(drawable);
- mEditUserPhotoController = new EditUserPhotoController(fragment, userPhotoView,
- mSavedPhoto, drawable, mWaitingForActivityResult);
+ mEditUserPhotoController = createEditUserPhotoController(fragment, userPhotoView, drawable);
mEditUserInfoDialog = new AlertDialog.Builder(activity)
.setTitle(R.string.profile_info_settings_title)
.setView(content)
@@ -195,4 +194,11 @@
return mEditUserInfoDialog;
}
+
+ @VisibleForTesting
+ EditUserPhotoController createEditUserPhotoController(Fragment fragment,
+ ImageView userPhotoView, Drawable drawable) {
+ return new EditUserPhotoController(fragment, userPhotoView,
+ mSavedPhoto, drawable, mWaitingForActivityResult);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
index 88ed112..10d5f22 100644
--- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java
@@ -63,6 +63,8 @@
public void setUp() {
mContext = RuntimeEnvironment.application;
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "clazz";
mActivityInfo.metaData = new Bundle();
final Bundle args = new Bundle();
@@ -121,7 +123,6 @@
mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
mActivityInfo.metaData.putString("com.android.settings.intent.action",
Intent.ACTION_ASSIST);
- tile.intent = new Intent();
tile.userHandle = null;
mFragment.displayTile(tile);
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
index bee208f..da91a1d 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
@@ -106,6 +106,7 @@
anyInt(),
nullable(String.class),
any(VibrationEffect.class),
+ nullable(String.class),
nullable(AudioAttributes.class));
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
index a5422e7..9f81711 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceUpdaterTest.java
@@ -30,11 +30,8 @@
import com.android.settings.connecteddevice.DevicePreferenceCallback;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settingslib.bluetooth.A2dpProfile;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.HeadsetProfile;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import com.android.settingslib.bluetooth.LocalBluetoothProfileManager;
import org.junit.Before;
import org.junit.Test;
@@ -61,12 +58,6 @@
private SettingsActivity mSettingsActivity;
@Mock
private LocalBluetoothManager mLocalManager;
- @Mock
- private LocalBluetoothProfileManager mLocalBluetoothProfileManager;
- @Mock
- private HeadsetProfile mHeadsetProfile;
- @Mock
- private A2dpProfile mA2dpProfile;
private Context mContext;
private BluetoothDeviceUpdater mBluetoothDeviceUpdater;
@@ -79,9 +70,6 @@
mContext = RuntimeEnvironment.application;
doReturn(mContext).when(mDashboardFragment).getContext();
when(mCachedBluetoothDevice.getDevice()).thenReturn(mBluetoothDevice);
- when(mLocalManager.getProfileManager()).thenReturn(mLocalBluetoothProfileManager);
- when(mLocalBluetoothProfileManager.getHeadsetProfile()).thenReturn(mHeadsetProfile);
- when(mLocalBluetoothProfileManager.getA2dpProfile()).thenReturn(mA2dpProfile);
mPreference = new BluetoothDevicePreference(mContext, mCachedBluetoothDevice, false);
mBluetoothDeviceUpdater =
diff --git a/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java b/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java
index 5b658a9..0f44c85 100644
--- a/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java
@@ -54,6 +54,8 @@
public void setUp() {
mContext = RuntimeEnvironment.application;
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "class";
mActivityInfo.applicationInfo = new ApplicationInfo();
mTileByComponentCache = new HashMap<>();
mCategoryByKeyMap = new HashMap<>();
@@ -130,18 +132,21 @@
// Create some fake tiles that are not sorted.
final String testPackage = "com.android.test";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 50;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class3";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 200;
+
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
@@ -163,18 +168,22 @@
final String testPackage1 = "com.android.test1";
final String testPackage2 = "com.android.test2";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+
+ mActivityInfo.packageName = testPackage2;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent =
- new Intent().setComponent(new ComponentName(testPackage2, "class1"));
tile1.priority = 100;
+
+ mActivityInfo.packageName = testPackage1;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent =
- new Intent().setComponent(new ComponentName(testPackage1, "class2"));
tile2.priority = 100;
+
+ mActivityInfo.packageName = testPackage1;
+ mActivityInfo.name = "class3";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent =
- new Intent().setComponent(new ComponentName(testPackage1, "class3"));
tile3.priority = 50;
+
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
@@ -194,18 +203,22 @@
// Create some fake tiles that are not sorted.
final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 100;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class3";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 50;
+
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
@@ -226,17 +239,21 @@
final String testPackage = mContext.getPackageName();
final String testPackage2 = "com.google.test2";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent = new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 2;
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent = new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 1;
+ mActivityInfo.packageName = testPackage2;
+ mActivityInfo.name = "class0";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent = new Intent().setComponent(new ComponentName(testPackage2, "class0"));
tile3.priority = 0;
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class3";
final Tile tile4 = new Tile(mActivityInfo, category.key);
- tile4.intent = new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile4.priority = -1;
category.addTile(tile1);
category.addTile(tile2);
@@ -261,15 +278,21 @@
final String testPackage2 = "com.google.test2";
final String testPackage3 = "com.abcde.test3";
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+ mActivityInfo.packageName = testPackage2;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent = new Intent().setComponent(new ComponentName(testPackage2, "class1"));
tile1.priority = 1;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent = new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 1;
+
+ mActivityInfo.packageName = testPackage3;
+ mActivityInfo.name = "class3";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent = new Intent().setComponent(new ComponentName(testPackage3, "class3"));
tile3.priority = 1;
+
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
@@ -289,18 +312,21 @@
// Create some unique tiles
final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class2";
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 100;
+
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class3";
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 50;
+
category.addTile(tile1);
category.addTile(tile2);
category.addTile(tile3);
@@ -316,17 +342,13 @@
// Create tiles pointing to same intent.
final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
+ mActivityInfo.packageName = testPackage;
+ mActivityInfo.name = "class1";
final Tile tile1 = new Tile(mActivityInfo, category.key);
- tile1.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
final Tile tile2 = new Tile(mActivityInfo, category.key);
- tile2.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile2.priority = 100;
final Tile tile3 = new Tile(mActivityInfo, category.key);
- tile3.intent =
- new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile3.priority = 50;
category.addTile(tile1);
category.addTile(tile2);
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
index 95eba63..8f10af7 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java
@@ -92,6 +92,8 @@
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "class";
mActivityInfo.metaData = new Bundle();
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
@@ -242,6 +244,30 @@
}
@Test
+ public void onBindTile_externalTileWithBackgroundColorRawValue_shouldUpdateIcon() {
+ final Context context = spy(RuntimeEnvironment.application);
+ final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
+ final DashboardAdapter.DashboardItemHolder holder =
+ new DashboardAdapter.DashboardItemHolder(view);
+ final Tile tile = spy(new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE));
+ tile.getMetaData().putInt(DashboardAdapter.META_DATA_PREFERENCE_ICON_BACKGROUND_ARGB,
+ 0xff0000);
+ doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
+ .when(tile).getIcon(context);
+ final IconCache iconCache = new IconCache(context);
+ mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
+ null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
+ ReflectionHelpers.setField(mDashboardAdapter, "mCache", iconCache);
+
+ doReturn("another.package").when(context).getPackageName();
+ mDashboardAdapter.onBindTile(holder, tile);
+
+ final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
+ tile.getIcon(context));
+ assertThat(homepageIcon.mBackgroundColor).isEqualTo(0xff0000);
+ }
+
+ @Test
public void onBindTile_externalTileWithBackgroundColorHint_shouldUpdateIcon() {
final Context context = spy(RuntimeEnvironment.application);
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
index f3601c4..12411a0 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java
@@ -34,7 +34,6 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -101,6 +100,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "class";
mActivityInfo.metaData = new Bundle();
doReturn(mPackageManager).when(mContext).getPackageManager();
when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
@@ -140,8 +141,6 @@
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.priority = 10;
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
preference, tile, "123", Preference.DEFAULT_ORDER);
@@ -158,8 +157,6 @@
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
tile.userHandle.add(mock(UserHandle.class));
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
when(mActivity.getApplicationContext().getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
@@ -177,8 +174,6 @@
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
@@ -198,12 +193,10 @@
@Test
public void bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog() {
final Preference preference = new Preference(RuntimeEnvironment.application);
+ mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
- tile.intent = new Intent();
- tile.intent.setComponent(
- new ComponentName(RuntimeEnvironment.application.getPackageName(), "class"));
when(mActivity.getSystemService(Context.USER_SERVICE))
.thenReturn(mUserManager);
@@ -234,8 +227,6 @@
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER);
@@ -247,8 +238,6 @@
public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER);
@@ -261,8 +250,6 @@
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.summary = "test";
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /*key */, Preference.DEFAULT_ORDER);
@@ -274,8 +261,6 @@
public void bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProvider() {
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_SUMMARY_URI,
"content://com.android.settings/tile_summary");
@@ -290,8 +275,6 @@
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.key = "key";
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
preference, tile, null /* key */, Preference.DEFAULT_ORDER);
@@ -302,11 +285,9 @@
@Config(shadows = {ShadowTileUtils.class, ShadowThreadUtils.class})
public void bindPreference_withIconUri_shouldLoadIconFromContentProvider() {
final Preference preference = new Preference(RuntimeEnvironment.application);
+ mActivityInfo.packageName = RuntimeEnvironment.application.getPackageName();
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.key = "key";
- tile.intent = new Intent();
- tile.intent.setComponent(
- new ComponentName(RuntimeEnvironment.application.getPackageName(), "class"));
mActivityInfo.metaData.putString(TileUtils.META_DATA_PREFERENCE_ICON_URI,
"content://com.android.settings/tile_icon");
mImpl.bindIcon(preference, tile);
@@ -357,8 +338,6 @@
final Preference preference = new Preference(RuntimeEnvironment.application);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.key = "key";
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
tile.userHandle = null;
mImpl.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.SETTINGS_GESTURES,
@@ -382,8 +361,6 @@
final Preference preference = new Preference(application.getApplicationContext());
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.key = "key";
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
mActivityInfo.metaData.putString("com.android.settings.intent.action", "TestAction");
tile.userHandle = null;
@@ -457,8 +434,6 @@
@Test
public void openTileIntent_profileSelectionDialog_shouldShow() {
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(new UserHandle(10));
@@ -474,8 +449,6 @@
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(new UserHandle(10));
@@ -491,8 +464,6 @@
public void openTileIntent_profileSelectionDialog_shouldNotShow() {
mActivityInfo.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
- tile.intent.setComponent(new ComponentName("pkg", "class"));
final ArrayList<UserHandle> handles = new ArrayList<>();
handles.add(new UserHandle(0));
handles.add(new UserHandle(10));
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
index 90bd7db..8182a1c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java
@@ -67,6 +67,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "class";
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mDashboardCategory = new DashboardCategory("key");
mDashboardCategory.addTile(new Tile(mActivityInfo, mDashboardCategory.key));
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
index 543bfdb..646643b 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
@@ -43,7 +43,10 @@
public void SetUp() {
mDashboardItemAnimator = new DashboardItemAnimator();
mViewHolder = new ViewHolder(new TextView(RuntimeEnvironment.application));
- mViewHolder.itemView.setTag(new Tile(new ActivityInfo(), CategoryKey.CATEGORY_HOMEPAGE));
+ final ActivityInfo activityInfo = new ActivityInfo();
+ activityInfo.packageName = "pkg";
+ activityInfo.name = "class";
+ mViewHolder.itemView.setTag(new Tile(activityInfo, CategoryKey.CATEGORY_HOMEPAGE));
}
@Test
diff --git a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
index e207cab..a4fd8d1 100644
--- a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java
@@ -22,7 +22,6 @@
import static org.mockito.Mockito.when;
import android.app.Activity;
-import android.content.Intent;
import android.content.pm.ActivityInfo;
import com.android.settings.testutils.FakeFeatureFactory;
@@ -52,8 +51,10 @@
public void SetUp() {
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
-
- mTile = new Tile(new ActivityInfo(), CategoryKey.CATEGORY_HOMEPAGE);
+ final ActivityInfo activityInfo = new ActivityInfo();
+ activityInfo.packageName = "pkg";
+ activityInfo.name = "class";
+ mTile = new Tile(activityInfo, CategoryKey.CATEGORY_HOMEPAGE);
mTile.summary = SUMMARY_1;
mCallbackInvoked = false;
@@ -86,9 +87,11 @@
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
final String testSummary = "test_summary";
final DashboardCategory category = new DashboardCategory(CategoryKey.CATEGORY_HOMEPAGE);
- final Tile tile = new Tile(new ActivityInfo(), category.key);
+ final ActivityInfo activityInfo = new ActivityInfo();
+ activityInfo.packageName = "pkg";
+ activityInfo.name = "cls";
+ final Tile tile = new Tile(activityInfo, category.key);
tile.key = "123";
- tile.intent = new Intent();
category.addTile(tile);
when(mFeatureFactory.dashboardFeatureProvider.getDashboardKeyForTile(tile))
.thenReturn(tile.key);
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
index 4c2ef42..8d7f841 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectDialogTest.java
@@ -24,7 +24,6 @@
import static org.mockito.Mockito.when;
import android.content.Context;
-import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.UserInfo;
import android.os.UserHandle;
@@ -51,6 +50,8 @@
@Mock
private UserManager mUserManager;
+ private ActivityInfo mActivityInfo;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
@@ -58,12 +59,15 @@
final UserInfo userInfo = new UserInfo(
NORMAL_USER.getIdentifier(), "test_user", UserInfo.FLAG_RESTRICTED);
when(mUserManager.getUserInfo(NORMAL_USER.getIdentifier())).thenReturn(userInfo);
+ mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "cls";
+
}
@Test
public void updateUserHandlesIfNeeded_Normal() {
- final Tile tile = new Tile(new ActivityInfo(), CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.userHandle.add(NORMAL_USER);
ProfileSelectDialog.updateUserHandlesIfNeeded(mContext, tile);
@@ -75,8 +79,7 @@
@Test
public void updateUserHandlesIfNeeded_Remove() {
- final Tile tile = new Tile(new ActivityInfo(), CategoryKey.CATEGORY_HOMEPAGE);
- tile.intent = new Intent();
+ final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_HOMEPAGE);
tile.userHandle.add(REMOVED_USER);
tile.userHandle.add(NORMAL_USER);
tile.userHandle.add(REMOVED_USER);
diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
index ea1af69..5fdf458 100644
--- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java
@@ -78,6 +78,8 @@
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
mActivityInfo = new ActivityInfo();
+ mActivityInfo.packageName = "pkg";
+ mActivityInfo.name = "class";
when(mContext.getPackageManager()).thenReturn(mPackageManager);
// Explicit casting to object due to MockitoCast bug
when((Object) mContext.getSystemService(FingerprintManager.class))
diff --git a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java
index bbb2142..b9d2978 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeDurationPreferenceControllerTest.java
@@ -16,8 +16,8 @@
package com.android.settings.notification;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.app.NotificationManager;
@@ -38,10 +38,6 @@
import org.robolectric.shadows.ShadowApplication;
import org.robolectric.util.ReflectionHelpers;
-import androidx.fragment.app.FragmentManager;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceScreen;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class ZenModeDurationPreferenceControllerTest {
private ZenModeDurationPreferenceController mController;
@@ -51,11 +47,7 @@
@Mock
private NotificationManager mNotificationManager;
@Mock
- private Preference mockPref;
- @Mock
private NotificationManager.Policy mPolicy;
- @Mock
- private PreferenceScreen mPreferenceScreen;
private ContentResolver mContentResolver;
private Context mContext;
@@ -67,34 +59,27 @@
mContext = shadowApplication.getApplicationContext();
mContentResolver = RuntimeEnvironment.application.getContentResolver();
- mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class),
- mock(FragmentManager.class));
+ mController = new ZenModeDurationPreferenceController(mContext, mock(Lifecycle.class));
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
- when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
- mockPref);
- mController.displayPreference(mPreferenceScreen);
}
@Test
public void updateState_DurationForever() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
Settings.Secure.ZEN_DURATION_FOREVER);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
- verify(mockPref).setSummary(mContext.getString(R.string.zen_mode_duration_summary_forever));
+ assertEquals(mContext.getString(R.string.zen_mode_duration_summary_forever),
+ mController.getSummary());
}
@Test
public void updateState_DurationPrompt() {
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
Settings.Secure.ZEN_DURATION_PROMPT);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
- verify(mockPref).setSummary(mContext.getString(
- R.string.zen_mode_duration_summary_always_prompt));
+ assertEquals(mContext.getString(R.string.zen_mode_duration_summary_always_prompt),
+ mController.getSummary());
}
@Test
@@ -102,10 +87,8 @@
int zenDuration = 45;
Settings.Secure.putInt(mContentResolver, Settings.Secure.ZEN_DURATION,
zenDuration);
- final Preference mockPref = mock(Preference.class);
- mController.updateState(mockPref);
- verify(mockPref).setSummary(mContext.getResources().getString(
- R.string.zen_mode_duration_summary_time_minutes, zenDuration));
+ assertEquals(mContext.getString(R.string.zen_mode_duration_summary_time_minutes,
+ zenDuration), mController.getSummary());
}
-}
\ No newline at end of file
+}
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowVibrator.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowVibrator.java
index 9046720..69e08d5 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowVibrator.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowVibrator.java
@@ -50,7 +50,8 @@
public final Vibrator delegate = mock(Vibrator.class);
@Implementation
- public void vibrate(int uid, String opPkg, VibrationEffect vibe, AudioAttributes attributes) {
- delegate.vibrate(uid, opPkg, vibe, attributes);
+ public void vibrate(int uid, String opPkg, VibrationEffect vibe, String reason,
+ AudioAttributes attributes) {
+ delegate.vibrate(uid, opPkg, vibe, reason, attributes);
}
}
diff --git a/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java b/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java
new file mode 100644
index 0000000..2e205f8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/users/EditUserInfoControllerTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.users;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.UserInfo;
+import android.graphics.drawable.Drawable;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.ImageView;
+
+import com.android.settings.R;
+import com.android.settings.testutils.Robolectric;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowUserManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = {ShadowUserManager.class})
+public class EditUserInfoControllerTest {
+ @Mock
+ private Fragment mFragment;
+ @Mock
+ private LayoutInflater mInflater;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private UserInfo mUserInfo;
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private View mDialogContent;
+ @Mock
+ private EditText mUserName;
+ @Mock
+ private ImageView mPhotoView;
+ @Mock
+ private Drawable mCurrentIcon;
+
+ private ShadowUserManager mUserManager;
+ private FragmentActivity mActivity;
+ private TestEditUserInfoController mController;
+
+ public class TestEditUserInfoController extends EditUserInfoController {
+ private EditUserPhotoController mPhotoController;
+
+ public EditUserPhotoController getPhotoController() {
+ return mPhotoController;
+ }
+
+ @Override
+ protected EditUserPhotoController createEditUserPhotoController(Fragment fragment,
+ ImageView userPhotoView, Drawable drawable) {
+ mPhotoController = mock(EditUserPhotoController.class, Answers.RETURNS_DEEP_STUBS);
+ return mPhotoController;
+ }
+ }
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mUserManager = ShadowUserManager.getShadow();
+ mUserManager.setUserInfo(0, mUserInfo);
+ mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).get());
+ when(mFragment.getActivity()).thenReturn(mActivity);
+ when(mActivity.getLayoutInflater()).thenReturn(mInflater);
+ when(mInflater.inflate(eq(R.layout.edit_user_info_dialog_content), any())).thenReturn(
+ mDialogContent);
+ when(mDialogContent.findViewById(eq(R.id.user_name))).thenReturn(mUserName);
+ when(mDialogContent.findViewById(eq(R.id.user_photo))).thenReturn(mPhotoView);
+ when(mPhotoView.getContext()).thenReturn((Context) mActivity);
+ mController = new TestEditUserInfoController();
+ }
+
+ @After
+ public void tearDown() {
+ mUserManager.reset();
+ }
+
+ @Test
+ public void photoControllerOnActivityResult_whenWaiting_isCalled() {
+ mController.createDialog(mFragment, mCurrentIcon, "test user",
+ R.string.profile_info_settings_title, null, android.os.Process.myUserHandle());
+ mController.startingActivityForResult();
+ Intent resultData = new Intent();
+ mController.onActivityResult(0, 0, resultData);
+ EditUserPhotoController photoController = mController.getPhotoController();
+ assertThat(photoController).isNotNull();
+ verify(photoController).onActivityResult(eq(0), eq(0), same(resultData));
+ }
+}