Merge "settings(nfc): Remove NFC beam settings" into main
This commit is contained in:
@@ -3017,23 +3017,6 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- NFC settings -->
|
|
||||||
<activity
|
|
||||||
android:name="Settings$AndroidBeamSettingsActivity"
|
|
||||||
android:exported="true"
|
|
||||||
android:label="@string/android_beam_settings_title">
|
|
||||||
<intent-filter android:priority="1">
|
|
||||||
<action android:name="android.settings.NFCSHARING_SETTINGS" />
|
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
|
||||||
</intent-filter>
|
|
||||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
|
||||||
android:value="com.android.settings.nfc.AndroidBeam" />
|
|
||||||
<meta-data android:name="com.android.settings.HIGHLIGHT_MENU_KEY"
|
|
||||||
android:value="@string/menu_key_connected_devices"/>
|
|
||||||
<meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
|
|
||||||
android:value="true" />
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name="Settings$WifiDisplaySettingsActivity"
|
android:name="Settings$WifiDisplaySettingsActivity"
|
||||||
android:label="@string/wifi_display_settings_title"
|
android:label="@string/wifi_display_settings_title"
|
||||||
|
@@ -46,14 +46,6 @@
|
|||||||
settings:controller="com.android.settings.wfd.WifiDisplayPreferenceController"
|
settings:controller="com.android.settings.wfd.WifiDisplayPreferenceController"
|
||||||
settings:keywords="@string/keywords_wifi_display_settings"/>
|
settings:keywords="@string/keywords_wifi_display_settings"/>
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
|
||||||
android:fragment="com.android.settings.nfc.AndroidBeam"
|
|
||||||
android:key="android_beam_settings"
|
|
||||||
android:title="@string/android_beam_settings_title"
|
|
||||||
settings:controller="com.android.settings.nfc.AndroidBeamPreferenceController"
|
|
||||||
android:icon="@drawable/ic_android"
|
|
||||||
android:order="-5"/>
|
|
||||||
|
|
||||||
<com.android.settingslib.RestrictedPreference
|
<com.android.settingslib.RestrictedPreference
|
||||||
android:key="connected_device_printing"
|
android:key="connected_device_printing"
|
||||||
android:title="@string/print_settings"
|
android:title="@string/print_settings"
|
||||||
|
@@ -331,7 +331,6 @@ public class Settings extends SettingsActivity {
|
|||||||
public static class ConfigureWifiSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class ConfigureWifiSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class SavedAccessPointsSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class SavedAccessPointsSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class TextToSpeechSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class TextToSpeechSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class AndroidBeamSettingsActivity extends SettingsActivity { /* empty */ }
|
|
||||||
public static class WifiDisplaySettingsActivity extends SettingsActivity { /* empty */ }
|
public static class WifiDisplaySettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
public static class DreamSettingsActivity extends SettingsActivity { /* empty */ }
|
public static class DreamSettingsActivity extends SettingsActivity { /* empty */ }
|
||||||
/** Activity to manage communal settings */
|
/** Activity to manage communal settings */
|
||||||
|
@@ -17,12 +17,10 @@ package com.android.settings.connecteddevice;
|
|||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.nfc.AndroidBeamPreferenceController;
|
|
||||||
import com.android.settings.print.PrintSettingPreferenceController;
|
import com.android.settings.print.PrintSettingPreferenceController;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.uwb.UwbPreferenceController;
|
import com.android.settings.uwb.UwbPreferenceController;
|
||||||
@@ -111,17 +109,6 @@ public class AdvancedConnectedDeviceDashboardFragment extends DashboardFragment
|
|||||||
return Arrays.asList(sir);
|
return Arrays.asList(sir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<String> getNonIndexableKeys(Context context) {
|
|
||||||
final List<String> keys = super.getNonIndexableKeys(context);
|
|
||||||
PackageManager pm = context.getPackageManager();
|
|
||||||
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
|
||||||
keys.add(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
}
|
|
||||||
|
|
||||||
return keys;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||||
Context context) {
|
Context context) {
|
||||||
|
@@ -141,7 +141,6 @@ import com.android.settings.network.apn.ApnSettings;
|
|||||||
import com.android.settings.network.telephony.MobileNetworkSettings;
|
import com.android.settings.network.telephony.MobileNetworkSettings;
|
||||||
import com.android.settings.network.telephony.NetworkSelectSettings;
|
import com.android.settings.network.telephony.NetworkSelectSettings;
|
||||||
import com.android.settings.network.tether.TetherSettings;
|
import com.android.settings.network.tether.TetherSettings;
|
||||||
import com.android.settings.nfc.AndroidBeam;
|
|
||||||
import com.android.settings.nfc.PaymentSettings;
|
import com.android.settings.nfc.PaymentSettings;
|
||||||
import com.android.settings.notification.ConfigureNotificationSettings;
|
import com.android.settings.notification.ConfigureNotificationSettings;
|
||||||
import com.android.settings.notification.NotificationAccessSettings;
|
import com.android.settings.notification.NotificationAccessSettings;
|
||||||
@@ -258,7 +257,6 @@ public class SettingsGateway {
|
|||||||
PrivateVolumeForget.class.getName(),
|
PrivateVolumeForget.class.getName(),
|
||||||
PublicVolumeSettings.class.getName(),
|
PublicVolumeSettings.class.getName(),
|
||||||
DevelopmentSettingsDashboardFragment.class.getName(),
|
DevelopmentSettingsDashboardFragment.class.getName(),
|
||||||
AndroidBeam.class.getName(),
|
|
||||||
WifiDisplaySettings.class.getName(),
|
WifiDisplaySettings.class.getName(),
|
||||||
PowerUsageSummary.class.getName(),
|
PowerUsageSummary.class.getName(),
|
||||||
AccountSyncSettings.class.getName(),
|
AccountSyncSettings.class.getName(),
|
||||||
|
@@ -1,148 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 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.nfc;
|
|
||||||
|
|
||||||
import static com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.Switch;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsActivity;
|
|
||||||
import com.android.settings.core.InstrumentedFragment;
|
|
||||||
import com.android.settings.enterprise.ActionDisabledByAdminDialogHelper;
|
|
||||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
|
||||||
import com.android.settingslib.HelpUtils;
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
|
||||||
import com.android.settingslib.widget.OnMainSwitchChangeListener;
|
|
||||||
|
|
||||||
public class AndroidBeam extends InstrumentedFragment
|
|
||||||
implements OnMainSwitchChangeListener {
|
|
||||||
private View mView;
|
|
||||||
private NfcAdapter mNfcAdapter;
|
|
||||||
private SettingsMainSwitchBar mSwitchBar;
|
|
||||||
private CharSequence mOldActivityTitle;
|
|
||||||
private boolean mBeamDisallowedByBase;
|
|
||||||
private boolean mBeamDisallowedByOnlyAdmin;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
final Context context = getActivity();
|
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
||||||
final PackageManager pm = context.getPackageManager();
|
|
||||||
if (mNfcAdapter == null || !pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM))
|
|
||||||
getActivity().finish();
|
|
||||||
setHasOptionsMenu(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
|
||||||
super.onCreateOptionsMenu(menu, inflater);
|
|
||||||
HelpUtils.prepareHelpMenuItem(getActivity(), menu, R.string.help_uri_beam,
|
|
||||||
getClass().getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
final EnforcedAdmin admin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
|
|
||||||
getActivity(), UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId());
|
|
||||||
final UserManager um = UserManager.get(getActivity());
|
|
||||||
mBeamDisallowedByBase = RestrictedLockUtilsInternal.hasBaseUserRestriction(getActivity(),
|
|
||||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId());
|
|
||||||
if (!mBeamDisallowedByBase && admin != null) {
|
|
||||||
new ActionDisabledByAdminDialogHelper(getActivity())
|
|
||||||
.prepareDialogBuilder(UserManager.DISALLOW_OUTGOING_BEAM, admin).show();
|
|
||||||
mBeamDisallowedByOnlyAdmin = true;
|
|
||||||
return new View(getContext());
|
|
||||||
}
|
|
||||||
mView = inflater.inflate(R.layout.preference_footer, container, false);
|
|
||||||
|
|
||||||
ImageView iconInfo = mView.findViewById(android.R.id.icon);
|
|
||||||
iconInfo.setImageResource(R.drawable.ic_info_outline_24dp);
|
|
||||||
TextView textInfo = mView.findViewById(android.R.id.title);
|
|
||||||
textInfo.setText(R.string.android_beam_explained);
|
|
||||||
|
|
||||||
return mView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
|
||||||
super.onActivityCreated(savedInstanceState);
|
|
||||||
SettingsActivity activity = (SettingsActivity) getActivity();
|
|
||||||
|
|
||||||
mOldActivityTitle = activity.getActionBar().getTitle();
|
|
||||||
|
|
||||||
mSwitchBar = activity.getSwitchBar();
|
|
||||||
if (mBeamDisallowedByOnlyAdmin) {
|
|
||||||
mSwitchBar.hide();
|
|
||||||
} else {
|
|
||||||
mSwitchBar.setChecked(!mBeamDisallowedByBase && mNfcAdapter.isNdefPushEnabled());
|
|
||||||
mSwitchBar.addOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.setEnabled(!mBeamDisallowedByBase);
|
|
||||||
mSwitchBar.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
activity.setTitle(R.string.android_beam_settings_title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyView() {
|
|
||||||
super.onDestroyView();
|
|
||||||
if (mOldActivityTitle != null) {
|
|
||||||
getActivity().getActionBar().setTitle(mOldActivityTitle);
|
|
||||||
}
|
|
||||||
if (!mBeamDisallowedByOnlyAdmin) {
|
|
||||||
mSwitchBar.removeOnSwitchChangeListener(this);
|
|
||||||
mSwitchBar.hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSwitchChanged(Switch switchView, boolean desiredState) {
|
|
||||||
boolean success = false;
|
|
||||||
mSwitchBar.setEnabled(false);
|
|
||||||
if (desiredState) {
|
|
||||||
success = mNfcAdapter.enableNdefPush();
|
|
||||||
} else {
|
|
||||||
success = mNfcAdapter.disableNdefPush();
|
|
||||||
}
|
|
||||||
if (success) {
|
|
||||||
mSwitchBar.setChecked(desiredState);
|
|
||||||
}
|
|
||||||
mSwitchBar.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return SettingsEnums.NFC_BEAM;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +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.nfc;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* AndroidBeanEnabler is a helper to manage the Android Beam preference. It turns on/off
|
|
||||||
* Android Beam and ensures the summary of the preference reflects the current state.
|
|
||||||
*/
|
|
||||||
public class AndroidBeamEnabler extends BaseNfcEnabler {
|
|
||||||
private final boolean mBeamDisallowedBySystem;
|
|
||||||
private final RestrictedPreference mPreference;
|
|
||||||
|
|
||||||
public AndroidBeamEnabler(Context context, RestrictedPreference preference) {
|
|
||||||
super(context);
|
|
||||||
mPreference = preference;
|
|
||||||
mBeamDisallowedBySystem = RestrictedLockUtilsInternal.hasBaseUserRestriction(context,
|
|
||||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId());
|
|
||||||
if (!isNfcAvailable()) {
|
|
||||||
// NFC is not supported
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (mBeamDisallowedBySystem) {
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void handleNfcStateChanged(int newState) {
|
|
||||||
switch (newState) {
|
|
||||||
case NfcAdapter.STATE_OFF:
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
mPreference.setSummary(R.string.nfc_disabled_summary);
|
|
||||||
break;
|
|
||||||
case NfcAdapter.STATE_ON:
|
|
||||||
if (mBeamDisallowedBySystem) {
|
|
||||||
mPreference.setDisabledByAdmin(null);
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
mPreference.checkRestrictionAndSetDisabled(UserManager.DISALLOW_OUTGOING_BEAM);
|
|
||||||
}
|
|
||||||
if (mNfcAdapter.isNdefPushEnabled() && mPreference.isEnabled()) {
|
|
||||||
mPreference.setSummary(R.string.android_beam_on_summary);
|
|
||||||
} else {
|
|
||||||
mPreference.setSummary(R.string.android_beam_off_summary);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case NfcAdapter.STATE_TURNING_ON:
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
break;
|
|
||||||
case NfcAdapter.STATE_TURNING_OFF:
|
|
||||||
mPreference.setEnabled(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,79 +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.nfc;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
|
||||||
|
|
||||||
public class AndroidBeamPreferenceController extends BasePreferenceController
|
|
||||||
implements LifecycleObserver, OnResume, OnPause {
|
|
||||||
|
|
||||||
public static final String KEY_ANDROID_BEAM_SETTINGS = "android_beam_settings";
|
|
||||||
private final NfcAdapter mNfcAdapter;
|
|
||||||
private AndroidBeamEnabler mAndroidBeamEnabler;
|
|
||||||
|
|
||||||
public AndroidBeamPreferenceController(Context context, String key) {
|
|
||||||
super(context, key);
|
|
||||||
mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
if (!isAvailable()) {
|
|
||||||
mAndroidBeamEnabler = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final RestrictedPreference restrictedPreference = screen.findPreference(getPreferenceKey());
|
|
||||||
mAndroidBeamEnabler = new AndroidBeamEnabler(mContext, restrictedPreference);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@AvailabilityStatus
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
PackageManager pm = mContext.getPackageManager();
|
|
||||||
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)) {
|
|
||||||
return UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
return mNfcAdapter != null
|
|
||||||
? AVAILABLE
|
|
||||||
: UNSUPPORTED_ON_DEVICE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
if (mAndroidBeamEnabler != null) {
|
|
||||||
mAndroidBeamEnabler.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
if (mAndroidBeamEnabler != null) {
|
|
||||||
mAndroidBeamEnabler.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@@ -23,7 +23,6 @@ import android.content.Context;
|
|||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
|
|
||||||
import com.android.settings.nfc.AndroidBeamPreferenceController;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
import com.android.settings.testutils.shadow.ShadowConnectivityManager;
|
||||||
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
||||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||||
@@ -78,14 +77,4 @@ public class AdvancedConnectedDeviceDashboardFragmentTest {
|
|||||||
public void testGetCategoryKey_returnCategoryDevice() {
|
public void testGetCategoryKey_returnCategoryDevice() {
|
||||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
|
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_DEVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchIndexProvider_correctNonIndexables() {
|
|
||||||
mShadowNfcAdapter.setSecureNfcSupported(true);
|
|
||||||
final List<String> niks =
|
|
||||||
AdvancedConnectedDeviceDashboardFragment.SEARCH_INDEX_DATA_PROVIDER
|
|
||||||
.getNonIndexableKeys(mContext);
|
|
||||||
|
|
||||||
assertThat(niks).contains(AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -1,175 +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.nfc;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.nfc.NfcManager;
|
|
||||||
import android.os.UserHandle;
|
|
||||||
import android.os.UserManager;
|
|
||||||
import android.provider.Settings;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.testutils.shadow.ShadowNfcAdapter;
|
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
|
||||||
import com.android.settingslib.RestrictedPreference;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.shadow.api.Shadow;
|
|
||||||
import org.robolectric.util.ReflectionHelpers;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Config(shadows = ShadowNfcAdapter.class)
|
|
||||||
public class AndroidBeamPreferenceControllerTest {
|
|
||||||
|
|
||||||
Context mContext;
|
|
||||||
@Mock
|
|
||||||
NfcManager mNfcManager;
|
|
||||||
@Mock
|
|
||||||
private UserManager mUserManager;
|
|
||||||
@Mock
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
@Mock
|
|
||||||
private PackageManager mPackageManager;
|
|
||||||
|
|
||||||
private RestrictedPreference mAndroidBeamPreference;
|
|
||||||
private AndroidBeamPreferenceController mAndroidBeamController;
|
|
||||||
private ShadowNfcAdapter mShadowNfcAdapter;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
mContext = spy(RuntimeEnvironment.application);
|
|
||||||
mShadowNfcAdapter = Shadow.extract(NfcAdapter.getDefaultAdapter(mContext));
|
|
||||||
|
|
||||||
when(mContext.getApplicationContext()).thenReturn(mContext);
|
|
||||||
when(mContext.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
|
||||||
when(mContext.getSystemService(Context.NFC_SERVICE)).thenReturn(mNfcManager);
|
|
||||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
|
||||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(false);
|
|
||||||
|
|
||||||
mAndroidBeamController = new AndroidBeamPreferenceController(mContext,
|
|
||||||
AndroidBeamPreferenceController.KEY_ANDROID_BEAM_SETTINGS);
|
|
||||||
mAndroidBeamPreference = new RestrictedPreference(RuntimeEnvironment.application);
|
|
||||||
when(mScreen.findPreference(mAndroidBeamController.getPreferenceKey())).thenReturn(
|
|
||||||
mAndroidBeamPreference);
|
|
||||||
when(mContext.getPackageManager()).thenReturn(mPackageManager);
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)).thenReturn(true);
|
|
||||||
|
|
||||||
Settings.Global.putString(mContext.getContentResolver(),
|
|
||||||
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
|
|
||||||
Settings.Global.RADIO_NFC);
|
|
||||||
Settings.Global.putInt(mContext.getContentResolver(),
|
|
||||||
Settings.Global.AIRPLANE_MODE_ON,
|
|
||||||
0);
|
|
||||||
mAndroidBeamController.displayPreference(mScreen);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_hasNfc_shouldReturnTrue() {
|
|
||||||
mShadowNfcAdapter.setEnabled(true);
|
|
||||||
assertThat(mAndroidBeamController.isAvailable()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_noNfcFeature_shouldReturnFalse() {
|
|
||||||
mShadowNfcAdapter.setEnabled(true);
|
|
||||||
when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_NFC_BEAM)).thenReturn(false);
|
|
||||||
assertThat(mAndroidBeamController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAvailable_noNfcAdapter_shouldReturnFalse() {
|
|
||||||
ReflectionHelpers.setField(mAndroidBeamController, "mNfcAdapter", null);
|
|
||||||
assertThat(mAndroidBeamController.isAvailable()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isBeamEnable_disAllowBeam_shouldReturnFalse() {
|
|
||||||
mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
|
|
||||||
|
|
||||||
when(RestrictedLockUtilsInternal.hasBaseUserRestriction(mContext,
|
|
||||||
UserManager.DISALLOW_OUTGOING_BEAM, UserHandle.myUserId())).thenReturn(true);
|
|
||||||
mAndroidBeamController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isBeamEnable_nfcStateOn_shouldReturnTrue() {
|
|
||||||
mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_ON);
|
|
||||||
try {
|
|
||||||
mAndroidBeamController.onResume();
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
// skip because it's just test
|
|
||||||
// it will meet NullPointerException in checkRestrictionAndSetDisabled
|
|
||||||
}
|
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isBeamEnable_nfcStateNotOn_shouldReturnFalse() {
|
|
||||||
mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_OFF);
|
|
||||||
mAndroidBeamController.onResume();
|
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
|
||||||
|
|
||||||
mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_ON);
|
|
||||||
mAndroidBeamController.onResume();
|
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
|
||||||
|
|
||||||
mShadowNfcAdapter.setAdapterState(NfcAdapter.STATE_TURNING_OFF);
|
|
||||||
mAndroidBeamController.onResume();
|
|
||||||
assertThat(mAndroidBeamPreference.isEnabled()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateNonIndexableKeys_available_shouldNotUpdate() {
|
|
||||||
mShadowNfcAdapter.setEnabled(true);
|
|
||||||
final List<String> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
mAndroidBeamController.updateNonIndexableKeys(keys);
|
|
||||||
|
|
||||||
assertThat(keys).isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateNonIndexableKeys_notAvailable_shouldUpdate() {
|
|
||||||
ReflectionHelpers.setField(mAndroidBeamController, "mNfcAdapter", null);
|
|
||||||
final List<String> keys = new ArrayList<>();
|
|
||||||
|
|
||||||
mAndroidBeamController.updateNonIndexableKeys(keys);
|
|
||||||
|
|
||||||
assertThat(keys).hasSize(1);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user