Merge "Clean up unused Sliceable.copy()" into tm-dev
This commit is contained in:
@@ -16,18 +16,12 @@
|
||||
|
||||
package com.android.settings.development;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
@@ -35,8 +29,6 @@ import com.android.settings.core.BasePreferenceController;
|
||||
* fragment.
|
||||
*/
|
||||
public class AdbDeviceNamePreferenceController extends BasePreferenceController {
|
||||
private static final String TAG = "AdbDeviceNamePrefCtrl";
|
||||
|
||||
private String mDeviceName;
|
||||
|
||||
public AdbDeviceNamePreferenceController(Context context, String key) {
|
||||
@@ -64,15 +56,4 @@ public class AdbDeviceNamePreferenceController extends BasePreferenceController
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("text", mDeviceName));
|
||||
|
||||
final String toast = mContext.getString(R.string.copyable_slice_toast,
|
||||
mDeviceName);
|
||||
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.password.ChooseLockSettingsHelper;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
@@ -104,11 +103,6 @@ public class BuildNumberPreferenceController extends BasePreferenceController im
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.build_number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
|
@@ -16,16 +16,11 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
@@ -98,17 +93,6 @@ public class PhoneNumberPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
clipboard.setPrimaryClip(ClipData.newPlainText("text", getFirstPhoneNumber()));
|
||||
|
||||
final String toast = mContext.getString(R.string.copyable_slice_toast,
|
||||
mContext.getText(R.string.status_number));
|
||||
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private CharSequence getFirstPhoneNumber() {
|
||||
final List<SubscriptionInfo> subscriptionInfoList =
|
||||
mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
|
@@ -28,10 +28,8 @@ import android.util.Log;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
|
||||
@@ -125,10 +123,4 @@ public class FirmwareVersionDetailPreferenceController extends BasePreferenceCon
|
||||
mFunDisallowedBySystem = RestrictedLockUtilsInternal.hasBaseUserRestriction(
|
||||
mContext, UserManager.DISALLOW_FUN, UserHandle.myUserId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.firmware_version));
|
||||
}
|
||||
}
|
||||
|
@@ -22,7 +22,6 @@ import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
|
||||
public class HardwareRevisionPreferenceController extends BasePreferenceController {
|
||||
|
||||
@@ -41,12 +40,6 @@ public class HardwareRevisionPreferenceController extends BasePreferenceControll
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.hardware_revision));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return SystemProperties.get("ro.boot.hardware.revision");
|
||||
|
@@ -21,7 +21,6 @@ import android.os.Build;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
|
||||
public class SerialNumberPreferenceController extends BasePreferenceController {
|
||||
|
||||
@@ -40,12 +39,6 @@ public class SerialNumberPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(),
|
||||
mContext.getText(R.string.status_serial_number));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return Build.getSerial();
|
||||
|
@@ -33,7 +33,6 @@ import androidx.preference.PreferenceScreen;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.deviceinfo.PhoneNumberSummaryPreference;
|
||||
import com.android.settings.slices.Sliceable;
|
||||
import com.android.settingslib.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -128,11 +127,6 @@ public class ImeiInfoPreferenceController extends BasePreferenceController {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void copy() {
|
||||
Sliceable.setCopyContent(mContext, getSummary(0), getTitle(0));
|
||||
}
|
||||
|
||||
private void updatePreference(Preference preference, int simSlot) {
|
||||
preference.setTitle(getTitle(simSlot));
|
||||
preference.setSummary(getSummary(simSlot));
|
||||
|
@@ -106,12 +106,6 @@ public class SettingsSliceProvider extends SliceProvider {
|
||||
public static final String ACTION_SLIDER_CHANGED =
|
||||
"com.android.settings.slice.action.SLIDER_CHANGED";
|
||||
|
||||
/**
|
||||
* Action passed for copy data for the Copyable Slices.
|
||||
*/
|
||||
public static final String ACTION_COPY =
|
||||
"com.android.settings.slice.action.COPY";
|
||||
|
||||
/**
|
||||
* Intent Extra passed for the key identifying the Setting Slice.
|
||||
*/
|
||||
|
@@ -19,7 +19,6 @@ package com.android.settings.slices;
|
||||
import static com.android.settings.bluetooth.BluetoothSliceBuilder.ACTION_BLUETOOTH_SLICE_CHANGED;
|
||||
import static com.android.settings.network.telephony.Enhanced4gLteSliceHelper.ACTION_ENHANCED_4G_LTE_CHANGED;
|
||||
import static com.android.settings.notification.zen.ZenModeSliceBuilder.ACTION_ZEN_MODE_SLICE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_COPY;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_SLIDER_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_CHANGED;
|
||||
import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
|
||||
@@ -100,9 +99,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
.getNewWifiCallingSliceHelper(context)
|
||||
.handleWifiCallingPreferenceChanged(intent);
|
||||
break;
|
||||
case ACTION_COPY:
|
||||
handleCopyAction(context, sliceUri, key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,29 +167,6 @@ public class SliceBroadcastReceiver extends BroadcastReceiver {
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
|
||||
private void handleCopyAction(Context context, Uri sliceUri, String key) {
|
||||
if (TextUtils.isEmpty(key)) {
|
||||
throw new IllegalArgumentException("No key passed to Intent for controller");
|
||||
}
|
||||
|
||||
final BasePreferenceController controller = getPreferenceController(context, key);
|
||||
|
||||
if (!(controller instanceof Sliceable)) {
|
||||
throw new IllegalArgumentException(
|
||||
"Copyable action passed for a non-copyable key:" + key);
|
||||
}
|
||||
|
||||
if (!controller.isAvailable()) {
|
||||
Log.w(TAG, "Can't update " + key + " since the setting is unavailable");
|
||||
if (!controller.hasAsyncUpdate()) {
|
||||
context.getContentResolver().notifyChange(sliceUri, null /* observer */);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
controller.copy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Log Slice value update events into MetricsFeatureProvider. The logging schema generally
|
||||
* follows the pattern in SharedPreferenceLogger.
|
||||
|
@@ -94,10 +94,6 @@ public class SliceBuilderUtils {
|
||||
return buildUnavailableSlice(context, sliceData);
|
||||
}
|
||||
|
||||
if (controller.isCopyableSlice()) {
|
||||
return buildCopyableSlice(context, sliceData, controller);
|
||||
}
|
||||
|
||||
switch (sliceData.getSliceType()) {
|
||||
case SliceData.SliceType.INTENT:
|
||||
return buildIntentSlice(context, sliceData, controller);
|
||||
@@ -350,32 +346,6 @@ public class SliceBuilderUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static Slice buildCopyableSlice(Context context, SliceData sliceData,
|
||||
BasePreferenceController controller) {
|
||||
final SliceAction copyableAction = getCopyableAction(context, sliceData);
|
||||
final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
|
||||
final IconCompat icon = getSafeIcon(context, sliceData);
|
||||
final SliceAction primaryAction = SliceAction.createDeeplink(contentIntent, icon,
|
||||
ListBuilder.ICON_IMAGE,
|
||||
sliceData.getTitle());
|
||||
final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
|
||||
@ColorInt final int color = Utils.getColorAccentDefaultColor(context);
|
||||
final Set<String> keywords = buildSliceKeywords(sliceData);
|
||||
final RowBuilder rowBuilder = new RowBuilder()
|
||||
.setTitle(sliceData.getTitle())
|
||||
.setPrimaryAction(primaryAction)
|
||||
.addEndItem(copyableAction);
|
||||
if (!Utils.isSettingsIntelligence(context)) {
|
||||
rowBuilder.setSubtitle(subtitleText);
|
||||
}
|
||||
|
||||
return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(color)
|
||||
.addRow(rowBuilder)
|
||||
.setKeywords(keywords)
|
||||
.build();
|
||||
}
|
||||
|
||||
static BasePreferenceController getPreferenceController(Context context,
|
||||
String controllerClassName, String controllerKey) {
|
||||
try {
|
||||
@@ -398,14 +368,6 @@ public class SliceBuilderUtils {
|
||||
return getActionIntent(context, SettingsSliceProvider.ACTION_SLIDER_CHANGED, sliceData);
|
||||
}
|
||||
|
||||
private static SliceAction getCopyableAction(Context context, SliceData sliceData) {
|
||||
final PendingIntent intent = getActionIntent(context,
|
||||
SettingsSliceProvider.ACTION_COPY, sliceData);
|
||||
final IconCompat icon = IconCompat.createWithResource(context,
|
||||
R.drawable.ic_content_copy_grey600_24dp);
|
||||
return SliceAction.create(intent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle());
|
||||
}
|
||||
|
||||
private static boolean isValidSummary(Context context, CharSequence summary) {
|
||||
if (summary == null || TextUtils.isEmpty(summary.toString().trim())) {
|
||||
return false;
|
||||
|
@@ -88,20 +88,6 @@ public interface Sliceable {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the key slice information to the clipboard.
|
||||
* It is highly recommended to show the toast to notify users when implemented this function.
|
||||
*/
|
||||
default void copy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not it's a copyable slice.
|
||||
*/
|
||||
default boolean isCopyableSlice() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not summary comes from something dynamic (ie, not hardcoded in xml)
|
||||
*/
|
||||
|
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.deviceinfo.hardwareinfo;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowSystemProperties;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowSystemProperties.class})
|
||||
public class HardwareRevisionPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private HardwareRevisionPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ShadowSystemProperties.override("ro.boot.hardware.revision", "robolectric");
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new HardwareRevisionPreferenceController(mContext,
|
||||
"hardware_info_device_revision");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_available() {
|
||||
when(mResources.getBoolean(R.bool.config_show_device_model)).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_unsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_show_device_model)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) 2022 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.deviceinfo.hardwareinfo;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SerialNumberPreferenceControllerTest {
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockito = MockitoJUnit.rule();
|
||||
@Spy
|
||||
private final Context mContext = ApplicationProvider.getApplicationContext();
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private SerialNumberPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new SerialNumberPreferenceController(mContext, "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_available() {
|
||||
when(mResources.getBoolean(R.bool.config_show_device_model)).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_unsupported() {
|
||||
when(mResources.getBoolean(R.bool.config_show_device_model)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
|
||||
}
|
||||
}
|
@@ -16,14 +16,11 @@
|
||||
|
||||
package com.android.settings.deviceinfo.imei;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
|
||||
import static android.telephony.TelephonyManager.PHONE_TYPE_GSM;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -31,7 +28,6 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
@@ -176,19 +172,4 @@ public class ImeiInfoPreferenceControllerTest {
|
||||
|
||||
verify(mFragment).getChildFragmentManager();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copy_shouldCopyImeiToClipboard() {
|
||||
ReflectionHelpers.setField(mController, "mIsMultiSim", false);
|
||||
final String meid = "125132215123";
|
||||
when(mTelephonyManager.getCurrentPhoneType(anyInt())).thenReturn(PHONE_TYPE_CDMA);
|
||||
when(mTelephonyManager.getMeid(anyInt())).thenReturn(meid);
|
||||
|
||||
mController.copy();
|
||||
|
||||
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
|
||||
CLIPBOARD_SERVICE);
|
||||
final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
|
||||
assertThat(data.toString()).isEqualTo(meid);
|
||||
}
|
||||
}
|
||||
|
@@ -40,7 +40,6 @@ import androidx.slice.widget.SliceLiveData;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.FakeCopyableController;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
import com.android.settings.testutils.FakeInvalidSliderController;
|
||||
import com.android.settings.testutils.FakeSliderController;
|
||||
@@ -68,12 +67,8 @@ public class SliceBuilderUtilsTest {
|
||||
private final Class TOGGLE_CONTROLLER = FakeToggleController.class;
|
||||
private final Class SLIDER_CONTROLLER = FakeSliderController.class;
|
||||
private final Class INVALID_SLIDER_CONTROLLER = FakeInvalidSliderController.class;
|
||||
private final Class COPYABLE_CONTROLLER = FakeCopyableController.class;
|
||||
private final Class CONTEXT_CONTROLLER = FakeContextOnlyPreferenceController.class;
|
||||
|
||||
private final String INTENT_PATH = SettingsSlicesContract.PATH_SETTING_INTENT + "/" + KEY;
|
||||
private final String ACTION_PATH = SettingsSlicesContract.PATH_SETTING_ACTION + "/" + KEY;
|
||||
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
@@ -121,20 +116,6 @@ public class SliceBuilderUtilsTest {
|
||||
SliceTester.testSettingsSliderSlice(mContext, slice, data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildCopyableSlice_returnsMatchingSlice() {
|
||||
final SliceData mockData = getMockData(COPYABLE_CONTROLLER, -1);
|
||||
|
||||
final Slice slice = SliceBuilderUtils.buildSlice(mContext, mockData);
|
||||
verify(mFeatureFactory.metricsFeatureProvider)
|
||||
.action(SettingsEnums.PAGE_UNKNOWN,
|
||||
MetricsEvent.ACTION_SETTINGS_SLICE_REQUESTED,
|
||||
SettingsEnums.PAGE_UNKNOWN,
|
||||
mockData.getKey(),
|
||||
0);
|
||||
SliceTester.testSettingsCopyableSlice(mContext, slice, mockData);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceController_buildsMatchingController() {
|
||||
final BasePreferenceController controller =
|
||||
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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.testutils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class FakeCopyableController extends BasePreferenceController {
|
||||
|
||||
public FakeCopyableController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -16,13 +16,10 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
@@ -30,8 +27,6 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.os.UserManager;
|
||||
@@ -53,7 +48,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -66,7 +60,6 @@ public class BuildNumberPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private UserManager mUserManager;
|
||||
private ClipboardManager mClipboardManager;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private Lifecycle mLifecycle;
|
||||
private FakeFeatureFactory mFactory;
|
||||
@@ -84,8 +77,6 @@ public class BuildNumberPreferenceControllerTest {
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mUserManager = (UserManager) spy(mContext.getSystemService(Context.USER_SERVICE));
|
||||
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
|
||||
mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
|
||||
doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
|
||||
|
||||
mFactory = FakeFeatureFactory.setupForTest();
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
@@ -197,16 +188,4 @@ public class BuildNumberPreferenceControllerTest {
|
||||
assertThat(activityResultHandled).isTrue();
|
||||
assertThat(DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(mContext)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void copy_shouldCopyBuildNumberToClipboard() {
|
||||
ArgumentCaptor<ClipData> captor = ArgumentCaptor.forClass(ClipData.class);
|
||||
doNothing().when(mClipboardManager).setPrimaryClip(captor.capture());
|
||||
|
||||
mController.copy();
|
||||
|
||||
final ClipData data = captor.getValue();
|
||||
assertThat(data.getItemAt(0).getText().toString()).isEqualTo(mController.getSummary());
|
||||
}
|
||||
}
|
||||
|
@@ -16,19 +16,14 @@
|
||||
|
||||
package com.android.settings.deviceinfo;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.telephony.SubscriptionInfo;
|
||||
@@ -39,7 +34,6 @@ import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
@@ -49,7 +43,6 @@ import com.android.settings.testutils.ResourcesUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -73,14 +66,11 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private PhoneNumberPreferenceController mController;
|
||||
private ClipboardManager mClipboardManager;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
|
||||
doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
|
||||
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
|
||||
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
|
||||
mController = spy(new PhoneNumberPreferenceController(mContext, "phone_number"));
|
||||
@@ -181,21 +171,4 @@ public class PhoneNumberPreferenceControllerTest {
|
||||
assertThat(primaryNumber).isEqualTo(ResourcesUtils.getResourcesString(
|
||||
mContext, "device_info_default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void copy_shouldCopyPhoneNumberToClipboard() {
|
||||
final List<SubscriptionInfo> list = new ArrayList<>();
|
||||
list.add(mSubscriptionInfo);
|
||||
when(mSubscriptionManager.getActiveSubscriptionInfoList()).thenReturn(list);
|
||||
final String phoneNumber = "1111111111";
|
||||
doReturn(phoneNumber).when(mController).getFormattedPhoneNumber(mSubscriptionInfo);
|
||||
ArgumentCaptor<ClipData> captor = ArgumentCaptor.forClass(ClipData.class);
|
||||
doNothing().when(mClipboardManager).setPrimaryClip(captor.capture());
|
||||
|
||||
mController.copy();
|
||||
|
||||
final CharSequence data = captor.getValue().getItemAt(0).getText();
|
||||
assertThat(phoneNumber.contentEquals(data)).isTrue();
|
||||
}
|
||||
}
|
||||
|
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* 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.deviceinfo.hardwareinfo;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Looper;
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class HardwareRevisionPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private HardwareRevisionPreferenceController mController;
|
||||
private ClipboardManager mClipboardManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
|
||||
doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
|
||||
mController = new HardwareRevisionPreferenceController(mContext,
|
||||
"hardware_info_device_revision");
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void copy_shouldCopyHardwareRevisionToClipboard() {
|
||||
ArgumentCaptor<ClipData> captor = ArgumentCaptor.forClass(ClipData.class);
|
||||
doNothing().when(mClipboardManager).setPrimaryClip(captor.capture());
|
||||
|
||||
mController.copy();
|
||||
|
||||
final ClipData data = captor.getValue();
|
||||
final String hardwareVer = SystemProperties.get("ro.boot.hardware.revision");
|
||||
assertThat(data.getItemAt(0).getText().toString()).isEqualTo(hardwareVer);
|
||||
}
|
||||
}
|
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* 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.deviceinfo.hardwareinfo;
|
||||
|
||||
import static android.content.Context.CLIPBOARD_SERVICE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Looper;
|
||||
|
||||
import androidx.test.annotation.UiThreadTest;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SerialNumberPreferenceControllerTest {
|
||||
|
||||
private Context mContext;
|
||||
private SerialNumberPreferenceController mController;
|
||||
private ClipboardManager mClipboardManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
if (Looper.myLooper() == null) {
|
||||
Looper.prepare();
|
||||
}
|
||||
mContext = spy(ApplicationProvider.getApplicationContext());
|
||||
mClipboardManager = (ClipboardManager) spy(mContext.getSystemService(CLIPBOARD_SERVICE));
|
||||
doReturn(mClipboardManager).when(mContext).getSystemService(CLIPBOARD_SERVICE);
|
||||
mController = new SerialNumberPreferenceController(mContext, "test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@UiThreadTest
|
||||
public void copy_shouldPutSerialNumberToClipBoard() {
|
||||
ArgumentCaptor<ClipData> captor = ArgumentCaptor.forClass(ClipData.class);
|
||||
doNothing().when(mClipboardManager).setPrimaryClip(captor.capture());
|
||||
|
||||
mController.copy();
|
||||
|
||||
final ClipData data = captor.getValue();
|
||||
assertThat(data.getItemAt(0).getText().toString()).contains(Build.getSerial());
|
||||
}
|
||||
}
|
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2020 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;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
public class FakeCopyableController extends BasePreferenceController {
|
||||
|
||||
public FakeCopyableController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return AVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSliceable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCopyableSlice() {
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user