Snap for 4754751 from d3ff522a0b to qt-release
Change-Id: I90e6aa1aea86ccd53862b01b3b699f1fd618d5b4
This commit is contained in:
@@ -1763,6 +1763,7 @@
|
||||
android:resource="@string/suggested_fingerprint_lock_settings_title" />
|
||||
<meta-data android:name="com.android.settings.summary"
|
||||
android:resource="@string/suggested_fingerprint_lock_settings_summary" />
|
||||
<meta-data android:name="com.android.settings.icon_tintable" android:value="true" />
|
||||
</activity>
|
||||
|
||||
<activity android:name=".password.ChooseLockGeneric$InternalActivity"
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFF44336"
|
||||
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13C19,5.13 15.87,2 12,2zM7,9c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88C9.92,16.21 7,11.85 7,9zM11,13h2v2h-2V13zM13,6h-2v5h2V6z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FF43A047"
|
||||
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13C19,5.13 15.87,2 12,2zM7,9c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88C9.92,16.21 7,11.85 7,9zM14.5,9c0,1.38 -1.12,2.5 -2.5,2.5S9.5,10.38 9.5,9s1.12,-2.5 2.5,-2.5S14.5,7.62 14.5,9z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFF44336"
|
||||
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7l0,-1h10V21zM17,18H7V6h10V18zM7,4V3h10v1H7zM16,12.5l-4,4l-4,-4l1.41,-1.41L11,12.67V8.5V8h2v0.5v4.17l1.59,-1.59L16,12.5z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FF43A047"
|
||||
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7l0,-1h10V21zM17,18H7V6h10V18zM7,4V3h10v1H7zM11.14,16l-3.84,-3.84l1.41,-1.42l2.43,2.42l4.16,-4.16l1.42,1.41L11.14,16z"/>
|
||||
</vector>
|
||||
|
||||
@@ -14,19 +14,12 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:pathData="M0,0l24,0l0,24l-24,0z"
|
||||
android:strokeColor="#000000"
|
||||
android:fillColor="#00000000"
|
||||
android:strokeWidth="1.33333335e-11"
|
||||
android:strokeAlpha="0.00784313771"/>
|
||||
<path
|
||||
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3L5,21C5,22.1 5.9,23 7,23L17,23C18.1,23 19,22.1 19,21L19,3C19,1.9 18.1,1.01 17,1.01ZM17,19L7,19L7,5L17,5L17,19ZM13.143,17.714L10.857,17.714L10.857,15.429L13.143,15.429L13.143,17.714ZM13.143,13.143L10.857,13.143L10.857,6.286L13.143,6.286L13.143,13.143Z"
|
||||
android:strokeColor="#00000000"
|
||||
android:fillColor="#F09300"
|
||||
android:strokeWidth="1"/>
|
||||
android:fillColor="#FFF44336"
|
||||
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7l0,-1h10V21zM17,18H7V6h10V18zM7,4V3h10v1H7zM11,15h2v2h-2V15zM13,8h-2v5h2V8z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFF44336"
|
||||
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7l0,-1h10V21zM17,18H7V6h10V18zM7,4V3h10v1H7zM11,15h2v2h-2V15zM13,8h-2v5h2V8z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFEF6C00"
|
||||
android:pathData="M12,4.24l6,3v4.1c0,3.9 -2.55,7.5 -6,8.59c-3.45,-1.09 -6,-4.7 -6,-8.59v-4.1L12,4.24M12,2L4,6v5.33c0,4.93 3.41,9.55 8,10.67c4.59,-1.12 8,-5.73 8,-10.67V6L12,2L12,2zM11,15h2v2h-2V15zM13,8h-2v5h2V8z"/>
|
||||
</vector>
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FF43A047"
|
||||
android:pathData="M11.14,16l-3.84,-3.84l1.41,-1.42l2.43,2.42l4.16,-4.16l1.42,1.41L11.14,16zM12,4.24l6,3v4.1c0,3.9 -2.55,7.5 -6,8.59c-3.45,-1.09 -6,-4.7 -6,-8.59v-4.1L12,4.24M12,2L4,6v5.33c0,4.93 3.41,9.55 8,10.67c4.59,-1.12 8,-5.73 8,-10.67V6L12,2L12,2z"/>
|
||||
</vector>
|
||||
|
||||
@@ -19,6 +19,6 @@
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:fillColor="#FFF44336"
|
||||
android:pathData="M15.5,9.91L14.09,8.5L12,10.59L9.91,8.5L8.5,9.91L10.59,12L8.5,14.09l1.41,1.41L12,13.42l2.09,2.08l1.41,-1.41L13.42,12L15.5,9.91zM12,4.24l6,3v4.1c0,3.9 -2.55,7.5 -6,8.59c-3.45,-1.09 -6,-4.7 -6,-8.59v-4.1L12,4.24M12,2L4,6v5.33c0,4.93 3.41,9.55 8,10.67c4.59,-1.12 8,-5.73 8,-10.67V6L12,2L12,2z"/>
|
||||
</vector>
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="16dp"
|
||||
android:paddingStart="16dp"
|
||||
android:paddingEnd="16dp"
|
||||
android:paddingStart="14dp"
|
||||
android:paddingEnd="14dp"
|
||||
android:paddingBottom="@dimen/dashboard_padding_bottom">
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
|
||||
@@ -16,5 +16,20 @@
|
||||
|
||||
<PreferenceScreen
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
||||
android:key="nfc_payment_settings_screen"
|
||||
android:title="@string/nfc_payment_settings_title">
|
||||
|
||||
<com.android.settings.nfc.NfcPaymentPreference
|
||||
android:key="nfc_payment"
|
||||
android:title="@string/nfc_payment_default"
|
||||
android:dialogTitle="@string/nfc_payment_pay_with"
|
||||
android:widgetLayout="@layout/preference_widget_gear"
|
||||
settings:controller="com.android.settings.nfc.NfcPaymentPreferenceController"/>
|
||||
|
||||
<DropDownPreference
|
||||
android:key="nfc_foreground"
|
||||
android:title="@string/nfc_payment_use_default"
|
||||
settings:controller="com.android.settings.nfc.NfcForegroundPreferenceController"/>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -141,6 +141,11 @@
|
||||
android:key="screen_locking_sounds"
|
||||
android:title="@string/screen_locking_sounds_title" />
|
||||
|
||||
<!-- Charging sounds -->
|
||||
<SwitchPreference
|
||||
android:key="charging_sounds"
|
||||
android:title="@string/charging_sounds_title" />
|
||||
|
||||
<!-- Docking sounds -->
|
||||
<SwitchPreference
|
||||
android:key="docking_sounds"
|
||||
|
||||
@@ -22,12 +22,13 @@ import android.content.Context;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.Preference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
public class AutoRestorePreferenceController extends TogglePreferenceController {
|
||||
private static final String TAG = "AutoRestorePrefCtrler";
|
||||
|
||||
@@ -36,10 +37,7 @@ public class AutoRestorePreferenceController extends TogglePreferenceController
|
||||
|
||||
public AutoRestorePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
|
||||
mPSCD = pData;
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,20 +17,18 @@
|
||||
package com.android.settings.backup;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class BackupDataPreferenceController extends BasePreferenceController {
|
||||
private PrivacySettingsConfigData mPSCD;
|
||||
|
||||
public BackupDataPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
|
||||
mPSCD = pData;
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,7 +24,6 @@ import android.content.Intent;
|
||||
import android.os.RemoteException;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.UserHandle;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
@@ -32,6 +31,8 @@ import com.android.settings.Settings.PrivacySettingsActivity;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
/**
|
||||
* Helper class for {@link BackupSettingsActivity} that interacts with {@link IBackupManager}.
|
||||
*/
|
||||
|
||||
@@ -18,20 +18,18 @@ package com.android.settings.backup;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class ConfigureAccountPreferenceController extends BasePreferenceController {
|
||||
private PrivacySettingsConfigData mPSCD;
|
||||
|
||||
public ConfigureAccountPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
|
||||
mPSCD = pData;
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,21 +17,17 @@
|
||||
package com.android.settings.backup;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class DataManagementPreferenceController extends BasePreferenceController {
|
||||
private PrivacySettingsConfigData mPSCD;
|
||||
private boolean mManageEnabled;
|
||||
|
||||
public DataManagementPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setPrivacySettingsConfigData(final PrivacySettingsConfigData pData) {
|
||||
mPSCD = pData;
|
||||
mManageEnabled = (mPSCD.getManageIntent() != null) && mPSCD.isBackupEnabled();
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,7 +35,8 @@ public class DataManagementPreferenceController extends BasePreferenceController
|
||||
if (!PrivacySettingsUtils.isAdminUser(mContext)) {
|
||||
return DISABLED_FOR_USER;
|
||||
}
|
||||
if (!mManageEnabled) {
|
||||
boolean manageEnabled = (mPSCD.getManageIntent() != null) && mPSCD.isBackupEnabled();
|
||||
if (!manageEnabled) {
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
return AVAILABLE;
|
||||
@@ -47,12 +44,13 @@ public class DataManagementPreferenceController extends BasePreferenceController
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (mManageEnabled) {
|
||||
preference.setIntent(mPSCD.getManageIntent());
|
||||
final String manageLabel = mPSCD.getManageLabel();
|
||||
if (manageLabel != null) {
|
||||
preference.setTitle(manageLabel);
|
||||
}
|
||||
if (!isAvailable()) {
|
||||
return;
|
||||
}
|
||||
preference.setIntent(mPSCD.getManageIntent());
|
||||
final String manageLabel = mPSCD.getManageLabel();
|
||||
if (manageLabel != null) {
|
||||
preference.setTitle(manageLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,15 +65,10 @@ public class PrivacySettings extends DashboardFragment {
|
||||
}
|
||||
|
||||
private void updatePrivacySettingsConfigData(final Context context) {
|
||||
final PrivacySettingsConfigData pData = new PrivacySettingsConfigData();
|
||||
if (PrivacySettingsUtils.isAdminUser(context)) {
|
||||
PrivacySettingsUtils.updatePrivacyBuffer(context, pData);
|
||||
PrivacySettingsUtils.updatePrivacyBuffer(context,
|
||||
PrivacySettingsConfigData.getInstance());
|
||||
}
|
||||
|
||||
use(BackupDataPreferenceController.class).setPrivacySettingsConfigData(pData);
|
||||
use(ConfigureAccountPreferenceController.class).setPrivacySettingsConfigData(pData);
|
||||
use(DataManagementPreferenceController.class).setPrivacySettingsConfigData(pData);
|
||||
use(AutoRestorePreferenceController.class).setPrivacySettingsConfigData(pData);
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
|
||||
@@ -19,6 +19,9 @@ package com.android.settings.backup;
|
||||
import android.content.Intent;
|
||||
|
||||
public class PrivacySettingsConfigData {
|
||||
|
||||
private static PrivacySettingsConfigData sInstance;
|
||||
|
||||
private boolean mBackupEnabled;
|
||||
private boolean mBackupGray;
|
||||
private Intent mConfigIntent;
|
||||
@@ -26,7 +29,7 @@ public class PrivacySettingsConfigData {
|
||||
private Intent mManageIntent;
|
||||
private String mManageLabel;
|
||||
|
||||
public PrivacySettingsConfigData() {
|
||||
private PrivacySettingsConfigData() {
|
||||
mBackupEnabled = false;
|
||||
mBackupGray = false;
|
||||
mConfigIntent = null;
|
||||
@@ -35,6 +38,13 @@ public class PrivacySettingsConfigData {
|
||||
mManageLabel = null;
|
||||
}
|
||||
|
||||
public static PrivacySettingsConfigData getInstance() {
|
||||
if (sInstance == null) {
|
||||
sInstance = new PrivacySettingsConfigData();
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public boolean isBackupEnabled() {
|
||||
return mBackupEnabled;
|
||||
}
|
||||
|
||||
@@ -133,6 +133,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
@Override
|
||||
public void bindPreferenceToTile(Activity activity, int sourceMetricsCategory, Preference pref,
|
||||
Tile tile, String key, int baseOrder) {
|
||||
if (pref == null) {
|
||||
return;
|
||||
}
|
||||
pref.setTitle(tile.title);
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
pref.setKey(key);
|
||||
@@ -239,7 +242,7 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
if (tile.icon != null) {
|
||||
preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
|
||||
} else if (tile.metaData != null
|
||||
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI))
|
||||
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
String packageName = null;
|
||||
if (tile.intent != null) {
|
||||
@@ -259,11 +262,11 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
return;
|
||||
}
|
||||
final Icon icon = Icon.createWithResource(iconInfo.first, iconInfo.second);
|
||||
ThreadUtils.postOnMainThread(() -> {
|
||||
preference.setIcon(icon.loadDrawable(preference.getContext()));
|
||||
}
|
||||
ThreadUtils.postOnMainThread(() ->
|
||||
preference.setIcon(icon.loadDrawable(preference.getContext()))
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void launchIntentOrSelectProfile(Activity activity, Tile tile, Intent intent,
|
||||
|
||||
@@ -34,6 +34,7 @@ import android.view.WindowManagerGlobal;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.android.internal.app.LocalePicker;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
import com.android.settingslib.development.SystemPropPoker;
|
||||
|
||||
public abstract class DevelopmentTiles extends TileService {
|
||||
@@ -50,7 +51,18 @@ public abstract class DevelopmentTiles extends TileService {
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
getQsTile().setState(isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
|
||||
final int state;
|
||||
if (!DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this)) {
|
||||
// Reset to disabled state if dev option is off.
|
||||
if (isEnabled()) {
|
||||
setIsEnabled(false);
|
||||
SystemPropPoker.getInstance().poke();
|
||||
}
|
||||
state = Tile.STATE_UNAVAILABLE;
|
||||
} else {
|
||||
state = isEnabled() ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
|
||||
}
|
||||
getQsTile().setState(state);
|
||||
getQsTile().updateTile();
|
||||
}
|
||||
|
||||
@@ -124,7 +136,8 @@ public abstract class DevelopmentTiles extends TileService {
|
||||
IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
|
||||
try {
|
||||
return wm.getAnimationScale(0) != 1;
|
||||
} catch (RemoteException e) { }
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -136,7 +149,8 @@ public abstract class DevelopmentTiles extends TileService {
|
||||
wm.setAnimationScale(0, scale);
|
||||
wm.setAnimationScale(1, scale);
|
||||
wm.setAnimationScale(2, scale);
|
||||
} catch (RemoteException e) { }
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,11 +19,8 @@ import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.nfc.NfcAdapter;
|
||||
import android.nfc.NfcManager;
|
||||
import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -31,7 +28,8 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import java.util.List;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public abstract class BaseNfcPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause {
|
||||
@@ -65,13 +63,6 @@ public abstract class BaseNfcPreferenceController extends AbstractPreferenceCont
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNonIndexableKeys(List<String> keys) {
|
||||
if (!isAvailable()) {
|
||||
keys.add(getPreferenceKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mNfcAdapter != null;
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.settings.nfc;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public class NfcForegroundPreference extends DropDownPreference implements
|
||||
PaymentBackend.Callback, Preference.OnPreferenceChangeListener {
|
||||
|
||||
private final PaymentBackend mPaymentBackend;
|
||||
public NfcForegroundPreference(Context context, PaymentBackend backend) {
|
||||
super(context);
|
||||
mPaymentBackend = backend;
|
||||
mPaymentBackend.registerCallback(this);
|
||||
|
||||
setTitle(getContext().getString(R.string.nfc_payment_use_default));
|
||||
setEntries(new CharSequence[] {
|
||||
getContext().getString(R.string.nfc_payment_favor_open),
|
||||
getContext().getString(R.string.nfc_payment_favor_default)
|
||||
});
|
||||
setEntryValues(new CharSequence[] { "1", "0" });
|
||||
refresh();
|
||||
setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentAppsChanged() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
boolean foregroundMode = mPaymentBackend.isForegroundMode();
|
||||
if (foregroundMode) {
|
||||
setValue("1");
|
||||
} else {
|
||||
setValue("0");
|
||||
}
|
||||
setSummary(getEntry());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String newValueString = (String) newValue;
|
||||
setSummary(getEntries()[findIndexOfValue(newValueString)]);
|
||||
mPaymentBackend.setForegroundMode(Integer.parseInt(newValueString) != 0);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class NfcForegroundPreferenceController extends BasePreferenceController implements
|
||||
PaymentBackend.Callback, Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private DropDownPreference mPreference;
|
||||
private PaymentBackend mPaymentBackend;
|
||||
|
||||
public NfcForegroundPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
public void setPaymentBackend(PaymentBackend backend) {
|
||||
mPaymentBackend = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mPaymentBackend != null) {
|
||||
mPaymentBackend.registerCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mPaymentBackend != null) {
|
||||
mPaymentBackend.unregisterCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
if (mPaymentBackend == null) {
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
final List<PaymentBackend.PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos();
|
||||
return (appInfos != null && !appInfos.isEmpty())
|
||||
? AVAILABLE
|
||||
: DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (DropDownPreference) screen.findPreference(getPreferenceKey());
|
||||
if (mPreference == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
mPreference.setEntries(new CharSequence[] {
|
||||
mContext.getText(R.string.nfc_payment_favor_open),
|
||||
mContext.getText(R.string.nfc_payment_favor_default)
|
||||
});
|
||||
mPreference.setEntryValues(new CharSequence[] {"1", "0"});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentAppsChanged() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
if (preference instanceof DropDownPreference) {
|
||||
((DropDownPreference) preference).setValue(
|
||||
mPaymentBackend.isForegroundMode() ? "1" : "0");
|
||||
}
|
||||
super.updateState(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mPreference.getEntry();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
if (!(preference instanceof DropDownPreference)) {
|
||||
return false;
|
||||
}
|
||||
final DropDownPreference pref = (DropDownPreference) preference;
|
||||
final String newValueString = (String) newValue;
|
||||
pref.setSummary(pref.getEntries()[pref.findIndexOfValue(newValueString)]);
|
||||
mPaymentBackend.setForegroundMode(Integer.parseInt(newValueString) != 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateNonIndexableKeys(List<String> keys) {
|
||||
final String key = getPreferenceKey();
|
||||
if (!TextUtils.isEmpty(key)) {
|
||||
keys.add(key);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,80 +16,49 @@
|
||||
package com.android.settings.nfc;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
|
||||
import com.android.settingslib.CustomDialogPreference;
|
||||
|
||||
import java.util.List;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
public class NfcPaymentPreference extends CustomDialogPreference implements
|
||||
PaymentBackend.Callback, View.OnClickListener {
|
||||
public class NfcPaymentPreference extends CustomDialogPreference {
|
||||
|
||||
private static final String TAG = "NfcPaymentPreference";
|
||||
private Listener mListener;
|
||||
|
||||
private final NfcPaymentAdapter mAdapter;
|
||||
private final Context mContext;
|
||||
private final LayoutInflater mLayoutInflater;
|
||||
private final PaymentBackend mPaymentBackend;
|
||||
interface Listener {
|
||||
void onBindViewHolder(PreferenceViewHolder view);
|
||||
|
||||
// Fields below only modified on UI thread
|
||||
private ImageView mSettingsButtonView;
|
||||
void onPrepareDialogBuilder(AlertDialog.Builder builder,
|
||||
DialogInterface.OnClickListener listener);
|
||||
}
|
||||
|
||||
public NfcPaymentPreference(Context context, PaymentBackend backend) {
|
||||
super(context, null);
|
||||
mPaymentBackend = backend;
|
||||
mContext = context;
|
||||
backend.registerCallback(this);
|
||||
mAdapter = new NfcPaymentAdapter();
|
||||
setDialogTitle(context.getString(R.string.nfc_payment_pay_with));
|
||||
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
setWidgetLayoutResource(R.layout.preference_widget_gear);
|
||||
public NfcPaymentPreference(Context context, AttributeSet attrs, int defStyleAttr,
|
||||
int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
refresh();
|
||||
public NfcPaymentPreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public NfcPaymentPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
void initialize(Listener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
mSettingsButtonView = (ImageView) view.findViewById(R.id.settings_button);
|
||||
mSettingsButtonView.setOnClickListener(this);
|
||||
|
||||
updateSettingsVisibility();
|
||||
}
|
||||
|
||||
/**
|
||||
* MUST be called on UI thread.
|
||||
*/
|
||||
public void refresh() {
|
||||
List<PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos();
|
||||
PaymentAppInfo defaultApp = mPaymentBackend.getDefaultApp();
|
||||
if (appInfos != null) {
|
||||
PaymentAppInfo[] apps = appInfos.toArray(new PaymentAppInfo[appInfos.size()]);
|
||||
mAdapter.updateApps(apps, defaultApp);
|
||||
if (mListener != null) {
|
||||
mListener.onBindViewHolder(view);
|
||||
}
|
||||
setTitle(R.string.nfc_payment_default);
|
||||
if (defaultApp != null) {
|
||||
setSummary(defaultApp.label);
|
||||
} else {
|
||||
setSummary(mContext.getString(R.string.nfc_payment_default_not_set));
|
||||
}
|
||||
updateSettingsVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,122 +66,8 @@ public class NfcPaymentPreference extends CustomDialogPreference implements
|
||||
DialogInterface.OnClickListener listener) {
|
||||
super.onPrepareDialogBuilder(builder, listener);
|
||||
|
||||
builder.setSingleChoiceItems(mAdapter, 0, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentAppsChanged() {
|
||||
refresh();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PaymentAppInfo defaultAppInfo = mPaymentBackend.getDefaultApp();
|
||||
if (defaultAppInfo != null && defaultAppInfo.settingsComponent != null) {
|
||||
Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
|
||||
settingsIntent.setComponent(defaultAppInfo.settingsComponent);
|
||||
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
mContext.startActivity(settingsIntent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.e(TAG, "Settings activity not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void updateSettingsVisibility() {
|
||||
if (mSettingsButtonView != null) {
|
||||
PaymentAppInfo defaultApp = mPaymentBackend.getDefaultApp();
|
||||
if (defaultApp == null || defaultApp.settingsComponent == null) {
|
||||
mSettingsButtonView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mSettingsButtonView.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NfcPaymentAdapter extends BaseAdapter implements CompoundButton.OnCheckedChangeListener,
|
||||
View.OnClickListener {
|
||||
// Only modified on UI thread
|
||||
private PaymentAppInfo[] appInfos;
|
||||
|
||||
public NfcPaymentAdapter() {
|
||||
}
|
||||
|
||||
public void updateApps(PaymentAppInfo[] appInfos, PaymentAppInfo currentDefault) {
|
||||
// Clone app infos, only add those with a banner
|
||||
this.appInfos = appInfos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return appInfos.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaymentAppInfo getItem(int i) {
|
||||
return appInfos[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return appInfos[i].componentName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
PaymentAppInfo appInfo = appInfos[position];
|
||||
if (convertView == null) {
|
||||
convertView = mLayoutInflater.inflate(
|
||||
R.layout.nfc_payment_option, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.imageView = (ImageView) convertView.findViewById(R.id.banner);
|
||||
holder.radioButton = (RadioButton) convertView.findViewById(R.id.button);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
holder.imageView.setImageDrawable(appInfo.banner);
|
||||
holder.imageView.setTag(appInfo);
|
||||
holder.imageView.setContentDescription(appInfo.label);
|
||||
holder.imageView.setOnClickListener(this);
|
||||
|
||||
// Prevent checked callback getting called on recycled views
|
||||
holder.radioButton.setOnCheckedChangeListener(null);
|
||||
holder.radioButton.setChecked(appInfo.isDefault);
|
||||
holder.radioButton.setContentDescription(appInfo.label);
|
||||
holder.radioButton.setOnCheckedChangeListener(this);
|
||||
holder.radioButton.setTag(appInfo);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
public class ViewHolder {
|
||||
public ImageView imageView;
|
||||
public RadioButton radioButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
PaymentAppInfo appInfo = (PaymentAppInfo) compoundButton.getTag();
|
||||
makeDefault(appInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PaymentAppInfo appInfo = (PaymentAppInfo) view.getTag();
|
||||
makeDefault(appInfo);
|
||||
}
|
||||
|
||||
void makeDefault(PaymentAppInfo appInfo) {
|
||||
if (!appInfo.isDefault) {
|
||||
mPaymentBackend.setDefaultPaymentApp(appInfo.componentName);
|
||||
}
|
||||
Dialog dialog = getDialog();
|
||||
if (dialog != null)
|
||||
dialog.dismiss();
|
||||
if (mListener != null) {
|
||||
mListener.onPrepareDialogBuilder(builder, listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
257
src/com/android/settings/nfc/NfcPaymentPreferenceController.java
Normal file
257
src/com/android/settings/nfc/NfcPaymentPreferenceController.java
Normal file
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
* 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.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RadioButton;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
public class NfcPaymentPreferenceController extends BasePreferenceController implements
|
||||
PaymentBackend.Callback, View.OnClickListener, NfcPaymentPreference.Listener,
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String TAG = "NfcPaymentController";
|
||||
|
||||
private final NfcPaymentAdapter mAdapter;
|
||||
private PaymentBackend mPaymentBackend;
|
||||
private NfcPaymentPreference mPreference;
|
||||
private ImageView mSettingsButtonView;
|
||||
|
||||
public NfcPaymentPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mAdapter = new NfcPaymentAdapter(context);
|
||||
}
|
||||
|
||||
public void setPaymentBackend(PaymentBackend backend) {
|
||||
mPaymentBackend = backend;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (mPaymentBackend != null) {
|
||||
mPaymentBackend.registerCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
if (mPaymentBackend != null) {
|
||||
mPaymentBackend.unregisterCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final PackageManager pm = mContext.getPackageManager();
|
||||
if (!pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
||||
return DISABLED_UNSUPPORTED;
|
||||
}
|
||||
if (mPaymentBackend == null) {
|
||||
mPaymentBackend = new PaymentBackend(mContext);
|
||||
}
|
||||
final List<PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos();
|
||||
return (appInfos != null && !appInfos.isEmpty())
|
||||
? AVAILABLE
|
||||
: DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (NfcPaymentPreference) screen.findPreference(getPreferenceKey());
|
||||
if (mPreference != null) {
|
||||
mPreference.initialize(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
mSettingsButtonView = (ImageView) view.findViewById(R.id.settings_button);
|
||||
mSettingsButtonView.setOnClickListener(this);
|
||||
|
||||
updateSettingsVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
final List<PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos();
|
||||
if (appInfos != null) {
|
||||
final PaymentAppInfo[] apps = appInfos.toArray(new PaymentAppInfo[appInfos.size()]);
|
||||
mAdapter.updateApps(apps);
|
||||
}
|
||||
super.updateState(preference);
|
||||
updateSettingsVisibility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
final PaymentAppInfo defaultApp = mPaymentBackend.getDefaultApp();
|
||||
if (defaultApp != null) {
|
||||
return defaultApp.label;
|
||||
} else {
|
||||
return mContext.getText(R.string.nfc_payment_default_not_set);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareDialogBuilder(AlertDialog.Builder builder,
|
||||
DialogInterface.OnClickListener listener) {
|
||||
builder.setSingleChoiceItems(mAdapter, 0, listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPaymentAppsChanged() {
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
final PaymentAppInfo defaultAppInfo = mPaymentBackend.getDefaultApp();
|
||||
if (defaultAppInfo != null && defaultAppInfo.settingsComponent != null) {
|
||||
final Intent settingsIntent = new Intent(Intent.ACTION_MAIN);
|
||||
settingsIntent.setComponent(defaultAppInfo.settingsComponent);
|
||||
settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
mContext.startActivity(settingsIntent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Log.e(TAG, "Settings activity not found.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateSettingsVisibility() {
|
||||
if (mSettingsButtonView != null) {
|
||||
final PaymentAppInfo defaultApp = mPaymentBackend.getDefaultApp();
|
||||
if (defaultApp == null || defaultApp.settingsComponent == null) {
|
||||
mSettingsButtonView.setVisibility(View.GONE);
|
||||
} else {
|
||||
mSettingsButtonView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class NfcPaymentAdapter extends BaseAdapter implements
|
||||
CompoundButton.OnCheckedChangeListener, View.OnClickListener {
|
||||
private final LayoutInflater mLayoutInflater;
|
||||
|
||||
// Only modified on UI thread
|
||||
private PaymentAppInfo[] appInfos;
|
||||
|
||||
public NfcPaymentAdapter(Context context) {
|
||||
mLayoutInflater = (LayoutInflater) context.getSystemService(
|
||||
Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
public void updateApps(PaymentAppInfo[] appInfos) {
|
||||
// Clone app infos, only add those with a banner
|
||||
this.appInfos = appInfos;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return (appInfos != null) ? appInfos.length : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaymentAppInfo getItem(int i) {
|
||||
return appInfos[i];
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return appInfos[i].componentName.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
ViewHolder holder;
|
||||
final PaymentAppInfo appInfo = appInfos[position];
|
||||
if (convertView == null) {
|
||||
convertView = mLayoutInflater.inflate(
|
||||
R.layout.nfc_payment_option, parent, false);
|
||||
holder = new ViewHolder();
|
||||
holder.imageView = convertView.findViewById(R.id.banner);
|
||||
holder.radioButton = convertView.findViewById(R.id.button);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (ViewHolder) convertView.getTag();
|
||||
}
|
||||
holder.imageView.setImageDrawable(appInfo.banner);
|
||||
holder.imageView.setTag(appInfo);
|
||||
holder.imageView.setContentDescription(appInfo.label);
|
||||
holder.imageView.setOnClickListener(this);
|
||||
|
||||
// Prevent checked callback getting called on recycled views
|
||||
holder.radioButton.setOnCheckedChangeListener(null);
|
||||
holder.radioButton.setChecked(appInfo.isDefault);
|
||||
holder.radioButton.setContentDescription(appInfo.label);
|
||||
holder.radioButton.setOnCheckedChangeListener(this);
|
||||
holder.radioButton.setTag(appInfo);
|
||||
return convertView;
|
||||
}
|
||||
|
||||
private class ViewHolder {
|
||||
public ImageView imageView;
|
||||
public RadioButton radioButton;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
PaymentAppInfo appInfo = (PaymentAppInfo) compoundButton.getTag();
|
||||
makeDefault(appInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
PaymentAppInfo appInfo = (PaymentAppInfo) view.getTag();
|
||||
makeDefault(appInfo);
|
||||
}
|
||||
|
||||
private void makeDefault(PaymentAppInfo appInfo) {
|
||||
if (!appInfo.isDefault) {
|
||||
mPaymentBackend.setDefaultPaymentApp(appInfo.componentName);
|
||||
}
|
||||
final Dialog dialog = mPreference.getDialog();
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,9 @@ import android.nfc.NfcAdapter;
|
||||
import android.nfc.cardemulation.ApduServiceInfo;
|
||||
import android.nfc.cardemulation.CardEmulation;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.SettingNotFoundException;
|
||||
|
||||
@@ -57,7 +59,7 @@ public class PaymentBackend {
|
||||
// Fields below only modified on UI thread
|
||||
private ArrayList<PaymentAppInfo> mAppInfos;
|
||||
private PaymentAppInfo mDefaultAppInfo;
|
||||
private ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
|
||||
private ArrayList<Callback> mCallbacks = new ArrayList<>();
|
||||
|
||||
public PaymentBackend(Context context) {
|
||||
mContext = context;
|
||||
@@ -102,7 +104,8 @@ public class PaymentBackend {
|
||||
appInfo.componentName = service.getComponent();
|
||||
String settingsActivity = service.getSettingsActivityName();
|
||||
if (settingsActivity != null) {
|
||||
appInfo.settingsComponent = new ComponentName(appInfo.componentName.getPackageName(),
|
||||
appInfo.settingsComponent = new ComponentName(
|
||||
appInfo.componentName.getPackageName(),
|
||||
settingsActivity);
|
||||
} else {
|
||||
appInfo.settingsComponent = null;
|
||||
@@ -162,7 +165,7 @@ public class PaymentBackend {
|
||||
|
||||
void setForegroundMode(boolean foreground) {
|
||||
Settings.Secure.putInt(mContext.getContentResolver(),
|
||||
Settings.Secure.NFC_PAYMENT_FOREGROUND, foreground ? 1 : 0) ;
|
||||
Settings.Secure.NFC_PAYMENT_FOREGROUND, foreground ? 1 : 0);
|
||||
}
|
||||
|
||||
ComponentName getDefaultPaymentApp() {
|
||||
@@ -182,14 +185,23 @@ public class PaymentBackend {
|
||||
refresh();
|
||||
}
|
||||
|
||||
private final Handler mHandler = new Handler() {
|
||||
@Override
|
||||
public void dispatchMessage(Message msg) {
|
||||
refresh();
|
||||
}
|
||||
};
|
||||
|
||||
private class SettingsPackageMonitor extends PackageMonitor {
|
||||
private Handler mHandler;
|
||||
|
||||
@Override
|
||||
public void register(Context context, Looper thread, UserHandle user,
|
||||
boolean externalStorage) {
|
||||
if (mHandler == null) {
|
||||
mHandler = new Handler(thread) {
|
||||
@Override
|
||||
public void dispatchMessage(Message msg) {
|
||||
refresh();
|
||||
}
|
||||
};
|
||||
}
|
||||
super.register(context, thread, user, externalStorage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPackageAdded(String packageName, int uid) {
|
||||
mHandler.obtainMessage().sendToTarget();
|
||||
@@ -210,4 +222,4 @@ public class PaymentBackend {
|
||||
mHandler.obtainMessage().sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,8 @@ package com.android.settings.nfc;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -31,23 +29,25 @@ import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.search.SearchIndexableRaw;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@SearchIndexable
|
||||
public class PaymentSettings extends SettingsPreferenceFragment implements Indexable {
|
||||
public class PaymentSettings extends DashboardFragment {
|
||||
public static final String TAG = "PaymentSettings";
|
||||
|
||||
static final String PAYMENT_KEY = "payment";
|
||||
|
||||
private PaymentBackend mPaymentBackend;
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return MetricsEvent.NFC_PAYMENT;
|
||||
@@ -59,24 +59,13 @@ public class PaymentSettings extends SettingsPreferenceFragment implements Index
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mPaymentBackend = new PaymentBackend(getActivity());
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
|
||||
List<PaymentBackend.PaymentAppInfo> appInfos = mPaymentBackend.getPaymentAppInfos();
|
||||
if (appInfos != null && appInfos.size() > 0) {
|
||||
NfcPaymentPreference preference =
|
||||
new NfcPaymentPreference(getPrefContext(), mPaymentBackend);
|
||||
preference.setKey(PAYMENT_KEY);
|
||||
screen.addPreference(preference);
|
||||
NfcForegroundPreference foreground = new NfcForegroundPreference(getPrefContext(),
|
||||
mPaymentBackend);
|
||||
screen.addPreference(foreground);
|
||||
}
|
||||
use(NfcPaymentPreferenceController.class).setPaymentBackend(mPaymentBackend);
|
||||
use(NfcForegroundPreferenceController.class).setPaymentBackend(mPaymentBackend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,31 +100,19 @@ public class PaymentSettings extends SettingsPreferenceFragment implements Index
|
||||
}
|
||||
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
|
||||
final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
|
||||
final Resources res = context.getResources();
|
||||
|
||||
// Add fragment title
|
||||
SearchIndexableRaw data = new SearchIndexableRaw(context);
|
||||
data.key = PAYMENT_KEY;
|
||||
data.title = res.getString(R.string.nfc_payment_settings_title);
|
||||
data.screenTitle = res.getString(R.string.nfc_payment_settings_title);
|
||||
data.keywords = res.getString(R.string.keywords_payment_settings);
|
||||
result.add(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getNonIndexableKeys(Context context) {
|
||||
final List<String> nonVisibleKeys = super.getNonIndexableKeys(context);
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
if (pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
|
||||
return nonVisibleKeys;
|
||||
new BaseSearchIndexProvider() {
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.nfc_payment_settings;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
nonVisibleKeys.add(PAYMENT_KEY);
|
||||
return nonVisibleKeys;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
final PackageManager pm = context.getPackageManager();
|
||||
return pm.hasSystemFeature(PackageManager.FEATURE_NFC);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -213,6 +213,8 @@ public class SoundSettings extends DashboardFragment {
|
||||
new DialPadTonePreferenceController(context, fragment, lifecycle);
|
||||
final ScreenLockSoundPreferenceController screenLockSoundPreferenceController =
|
||||
new ScreenLockSoundPreferenceController(context, fragment, lifecycle);
|
||||
final ChargingSoundPreferenceController chargingSoundPreferenceController =
|
||||
new ChargingSoundPreferenceController(context, fragment, lifecycle);
|
||||
final DockingSoundPreferenceController dockingSoundPreferenceController =
|
||||
new DockingSoundPreferenceController(context, fragment, lifecycle);
|
||||
final TouchSoundPreferenceController touchSoundPreferenceController =
|
||||
@@ -228,6 +230,7 @@ public class SoundSettings extends DashboardFragment {
|
||||
|
||||
controllers.add(dialPadTonePreferenceController);
|
||||
controllers.add(screenLockSoundPreferenceController);
|
||||
controllers.add(chargingSoundPreferenceController);
|
||||
controllers.add(dockingSoundPreferenceController);
|
||||
controllers.add(touchSoundPreferenceController);
|
||||
controllers.add(vibrateOnTouchPreferenceController);
|
||||
@@ -238,6 +241,7 @@ public class SoundSettings extends DashboardFragment {
|
||||
"other_sounds_and_vibrations_category").setChildren(
|
||||
Arrays.asList(dialPadTonePreferenceController,
|
||||
screenLockSoundPreferenceController,
|
||||
chargingSoundPreferenceController,
|
||||
dockingSoundPreferenceController,
|
||||
touchSoundPreferenceController,
|
||||
vibrateOnTouchPreferenceController,
|
||||
|
||||
@@ -19,7 +19,6 @@ package com.android.settings.backup;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -32,6 +31,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowPrivacySettingsUtils.class})
|
||||
public class AutoRestorePreferenceControllerTest {
|
||||
@@ -44,7 +45,7 @@ public class AutoRestorePreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPSCD = new PrivacySettingsConfigData();
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
mController = new AutoRestorePreferenceController(mContext,
|
||||
PrivacySettingsUtils.AUTO_RESTORE);
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
@@ -59,7 +60,7 @@ public class AutoRestorePreferenceControllerTest {
|
||||
public void updateState_backupEnabled_prefShouldBeEnabled() {
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ package com.android.settings.backup;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -34,6 +32,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowPrivacySettingsUtils.class})
|
||||
public class BackupDataPreferenceControllerTest {
|
||||
@@ -46,7 +46,7 @@ public class BackupDataPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPSCD = new PrivacySettingsConfigData();
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
mController = new BackupDataPreferenceController(mContext,
|
||||
PrivacySettingsUtils.BACKUP_DATA);
|
||||
mPreference = new Preference(mContext);
|
||||
@@ -61,7 +61,7 @@ public class BackupDataPreferenceControllerTest {
|
||||
public void updateState_backupEnabled_prefShouldBeEnabled() {
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
@@ -70,7 +70,7 @@ public class BackupDataPreferenceControllerTest {
|
||||
public void updateState_backupEnabled_prefShouldDisplayOnSummary() {
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_on));
|
||||
@@ -80,7 +80,7 @@ public class BackupDataPreferenceControllerTest {
|
||||
public void updateState_backupDisabled_prefShouldDisplayOffSummary() {
|
||||
mPSCD.setBackupEnabled(false);
|
||||
mPSCD.setBackupGray(false);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.accessibility_feature_state_off));
|
||||
|
||||
@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
@@ -35,6 +34,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowPrivacySettingsUtils.class})
|
||||
public class ConfigureAccountPreferenceControllerTest {
|
||||
@@ -51,7 +52,7 @@ public class ConfigureAccountPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPSCD = new PrivacySettingsConfigData();
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
mController = new ConfigureAccountPreferenceController(mContext,
|
||||
PrivacySettingsUtils.CONFIGURE_ACCOUNT);
|
||||
mPreference = new Preference(mContext);
|
||||
@@ -68,7 +69,7 @@ public class ConfigureAccountPreferenceControllerTest {
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setConfigIntent(mIntent);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
}
|
||||
@@ -80,7 +81,7 @@ public class ConfigureAccountPreferenceControllerTest {
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setConfigIntent(mIntent);
|
||||
mPSCD.setConfigSummary(null);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getString(R.string.backup_configure_account_default_summary));
|
||||
@@ -93,7 +94,7 @@ public class ConfigureAccountPreferenceControllerTest {
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setConfigIntent(mIntent);
|
||||
mPSCD.setConfigSummary(mTestSummary);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(mTestSummary);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -34,6 +33,8 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowPrivacySettingsUtils.class})
|
||||
public class DataManagementPreferenceControllerTest {
|
||||
@@ -56,7 +57,7 @@ public class DataManagementPreferenceControllerTest {
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mPSCD = new PrivacySettingsConfigData();
|
||||
mPSCD = PrivacySettingsConfigData.getInstance();
|
||||
mController = new DataManagementPreferenceController(mContext, KEY);
|
||||
mPreference = new Preference(mContext);
|
||||
mTitle = "Title";
|
||||
@@ -68,26 +69,25 @@ public class DataManagementPreferenceControllerTest {
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setManageIntent(mIntent);
|
||||
mPSCD.setManageLabel(mTitle);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
mController.updateState(mPreference);
|
||||
assertThat(mPreference.getTitle())
|
||||
.isEqualTo(mTitle);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isAdmiUser_backupEnabled_hadManageIntent_shouldBeAvailable() {
|
||||
public void getAvailabilityStatus_isAdmin_backupEnabled_hadManageIntent_shouldBeAvailable() {
|
||||
ShadowPrivacySettingsUtils.setIsAdminUser(true);
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setManageIntent(mIntent);
|
||||
mPSCD.setManageLabel(mTitle);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_isnotAdmiUser_shouldBeDisabledForUser() {
|
||||
public void getAvailabilityStatus_isNotAdminUser_shouldBeDisabledForUser() {
|
||||
ShadowPrivacySettingsUtils.setIsAdminUser(false);
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_FOR_USER);
|
||||
@@ -95,13 +95,13 @@ public class DataManagementPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void
|
||||
getAvailabilityStatus_isAdmiUser_backupEnabled_nullManageIntent_shouldBeDisabledUnsupported() {
|
||||
getAvailabilityStatus_isAdminUser_backupEnabled_nullManageIntent_shouldBeDisabledUnsupported() {
|
||||
ShadowPrivacySettingsUtils.setIsAdminUser(true);
|
||||
mPSCD.setBackupEnabled(true);
|
||||
mPSCD.setBackupGray(false);
|
||||
mPSCD.setManageIntent(null);
|
||||
mPSCD.setManageLabel(mTitle);
|
||||
mController.setPrivacySettingsConfigData(mPSCD);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(BasePreferenceController.DISABLED_UNSUPPORTED);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
@@ -214,6 +215,15 @@ public class DashboardFeatureProviderImplTest {
|
||||
.startActivityForResultAsUser(any(Intent.class), anyInt(), any(UserHandle.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_nullPreference_shouldIgnore() {
|
||||
final Tile tile = mock(Tile.class);
|
||||
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
|
||||
null, tile, "123", Preference.DEFAULT_ORDER);
|
||||
|
||||
verifyZeroInteractions(tile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
|
||||
final Preference preference = new Preference(RuntimeEnvironment.application);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.development.qstile;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.service.quicksettings.Tile;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.development.DevelopmentSettingsEnabler;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.Robolectric;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DevelopmentTilesTest {
|
||||
|
||||
@Mock
|
||||
private Tile mTile;
|
||||
private DevelopmentTiles mService;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mService = spy(Robolectric.setupService(DevelopmentTiles.ShowLayout.class));
|
||||
doReturn(mTile).when(mService).getQsTile();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void refresh_devOptionIsDisabled_shouldResetTileValue() {
|
||||
DevelopmentSettingsEnabler.setDevelopmentSettingsEnabled(mService, false);
|
||||
mService.setIsEnabled(true);
|
||||
|
||||
mService.refresh();
|
||||
|
||||
assertThat(mService.isEnabled()).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
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;
|
||||
|
||||
@@ -27,7 +26,6 @@ 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.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
@@ -44,6 +42,8 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AndroidBeamPreferenceControllerTest {
|
||||
|
||||
|
||||
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
* 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.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.preference.DropDownPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class NfcForegroundPreferenceControllerTest {
|
||||
|
||||
private static final String PREF_KEY = PaymentSettingsTest.FOREGROUND_KEY;
|
||||
|
||||
@Mock
|
||||
private PaymentBackend mPaymentBackend;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PackageManager mManager;
|
||||
|
||||
private Context mContext;
|
||||
private DropDownPreference mPreference;
|
||||
private NfcForegroundPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mManager);
|
||||
mController = new NfcForegroundPreferenceController(mContext, PREF_KEY);
|
||||
mPreference = new DropDownPreference(mContext);
|
||||
when(mScreen.findPreference(PREF_KEY)).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noNFC_DISABLED() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcForegroundPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noPaymentBackend_DISABLED() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcForegroundPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noPaymentApps_DISABLED() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(null);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcForegroundPreferenceController.AVAILABLE);
|
||||
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(new ArrayList<>());
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcForegroundPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
private void initPaymentApps() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
final ArrayList<PaymentBackend.PaymentAppInfo> appInfos = new ArrayList<>();
|
||||
appInfos.add(new PaymentBackend.PaymentAppInfo());
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(appInfos);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasPaymentApps_AVAILABLE() {
|
||||
initPaymentApps();
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(NfcForegroundPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegisterCallback() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
|
||||
mController.onStart();
|
||||
|
||||
verify(mPaymentBackend).registerCallback(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregisterCallback() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
mController.onStart();
|
||||
|
||||
mController.onStop();
|
||||
|
||||
verify(mPaymentBackend).unregisterCallback(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeOptions_shouldUpdateEntryAndSummary() {
|
||||
initPaymentApps();
|
||||
mController.displayPreference(mScreen);
|
||||
mController.onPaymentAppsChanged();
|
||||
|
||||
final CharSequence favorDefault = mContext.getText(R.string.nfc_payment_favor_default);
|
||||
final CharSequence favorOpen = mContext.getText(R.string.nfc_payment_favor_open);
|
||||
|
||||
assertThat(mPreference.getEntry()).isEqualTo(favorDefault);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(favorDefault);
|
||||
|
||||
mPreference.setValueIndex(0);
|
||||
mPreference.callChangeListener(mPreference.getEntryValues()[0]);
|
||||
verify(mPaymentBackend).setForegroundMode(true);
|
||||
assertThat(mPreference.getEntry()).isEqualTo(favorOpen);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(favorOpen);
|
||||
|
||||
mPreference.setValueIndex(1);
|
||||
mPreference.callChangeListener(mPreference.getEntryValues()[1]);
|
||||
verify(mPaymentBackend).setForegroundMode(false);
|
||||
assertThat(mPreference.getEntry()).isEqualTo(favorDefault);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(favorDefault);
|
||||
}
|
||||
}
|
||||
@@ -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 static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class NfcForegroundPreferenceTest {
|
||||
@Mock
|
||||
private PaymentBackend mPaymentBackend;
|
||||
|
||||
private Context mContext;
|
||||
private PreferenceScreen mScreen;
|
||||
private NfcForegroundPreference mPreference;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mScreen = spy(new PreferenceScreen(mContext, null));
|
||||
when(mScreen.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
|
||||
when(mPaymentBackend.isForegroundMode()).thenReturn(false);
|
||||
mPreference = new NfcForegroundPreference(mContext, mPaymentBackend);
|
||||
mScreen.addPreference(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTogglingMode() {
|
||||
String nfc_payment_favor_default = mContext.getString(R.string.nfc_payment_favor_default);
|
||||
String nfc_payment_favor_open = mContext.getString(R.string.nfc_payment_favor_open);
|
||||
|
||||
assertThat(mPreference.getEntry()).isEqualTo(nfc_payment_favor_default);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(nfc_payment_favor_default);
|
||||
|
||||
mPreference.setValueIndex(0);
|
||||
mPreference.callChangeListener(mPreference.getEntryValues()[0]);
|
||||
verify(mPaymentBackend).setForegroundMode(true);
|
||||
assertThat(mPreference.getEntry()).isEqualTo(nfc_payment_favor_open);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(nfc_payment_favor_open);
|
||||
|
||||
mPreference.setValueIndex(1);
|
||||
mPreference.callChangeListener(mPreference.getEntryValues()[1]);
|
||||
verify(mPaymentBackend).setForegroundMode(false);
|
||||
assertThat(mPreference.getEntry()).isEqualTo(nfc_payment_favor_default);
|
||||
assertThat(mPreference.getSummary()).isEqualTo(nfc_payment_favor_default);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* 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.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class NfcPaymentPreferenceControllerTest {
|
||||
|
||||
private static final String PREF_KEY = PaymentSettingsTest.PAYMENT_KEY;
|
||||
|
||||
@Mock
|
||||
private PaymentBackend mPaymentBackend;
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
@Mock
|
||||
private PackageManager mManager;
|
||||
|
||||
private Context mContext;
|
||||
private NfcPaymentPreference mPreference;
|
||||
private NfcPaymentPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mManager);
|
||||
mController = new NfcPaymentPreferenceController(mContext, PREF_KEY);
|
||||
mPreference = spy(new NfcPaymentPreference(mContext, null));
|
||||
when(mScreen.findPreference(PREF_KEY)).thenReturn(mPreference);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noNFC_DISABLED() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcPaymentPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_noPaymentApps_DISABLED() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(null);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcPaymentPreferenceController.AVAILABLE);
|
||||
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(new ArrayList<>());
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isNotEqualTo(NfcPaymentPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_hasPaymentApps_AVAILABLE() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
final ArrayList<PaymentAppInfo> appInfos = new ArrayList<>();
|
||||
appInfos.add(new PaymentAppInfo());
|
||||
when(mPaymentBackend.getPaymentAppInfos()).thenReturn(appInfos);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus())
|
||||
.isEqualTo(NfcPaymentPreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStart_shouldRegisterCallback() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
|
||||
mController.onStart();
|
||||
|
||||
verify(mPaymentBackend).registerCallback(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStop_shouldUnregisterCallback() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
mController.onStart();
|
||||
|
||||
mController.onStop();
|
||||
|
||||
verify(mPaymentBackend).unregisterCallback(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void displayPreference_shouldInitialize() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mPreference).initialize(mController);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPaymentAppsChanged_shouldRefreshSummary() {
|
||||
mController.setPaymentBackend(mPaymentBackend);
|
||||
mController.displayPreference(mScreen);
|
||||
when(mPaymentBackend.getDefaultApp()).thenReturn(null);
|
||||
|
||||
mController.onPaymentAppsChanged();
|
||||
|
||||
assertThat(mPreference.getSummary())
|
||||
.isEqualTo(mContext.getText(R.string.nfc_payment_default_not_set));
|
||||
|
||||
final PaymentAppInfo appInfo = new PaymentAppInfo();
|
||||
appInfo.label = "test label";
|
||||
when(mPaymentBackend.getDefaultApp()).thenReturn(appInfo);
|
||||
|
||||
mController.onPaymentAppsChanged();
|
||||
|
||||
assertThat(mPreference.getSummary()).isEqualTo(appInfo.label);
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,6 @@
|
||||
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;
|
||||
|
||||
@@ -26,8 +25,6 @@ import android.nfc.NfcAdapter;
|
||||
import android.nfc.NfcManager;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
import androidx.preference.SwitchPreference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -42,10 +39,13 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class NfcPreferenceControllerTest {
|
||||
|
||||
Context mContext;
|
||||
|
||||
@Mock
|
||||
private NfcAdapter mNfcAdapter;
|
||||
@Mock
|
||||
@@ -55,6 +55,7 @@ public class NfcPreferenceControllerTest {
|
||||
@Mock
|
||||
private PreferenceScreen mScreen;
|
||||
|
||||
private Context mContext;
|
||||
private SwitchPreference mNfcPreference;
|
||||
private NfcPreferenceController mNfcController;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
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;
|
||||
@@ -30,42 +31,66 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = PaymentSettingsTest.ShadowPaymentBackend.class)
|
||||
public class PaymentSettingsTest {
|
||||
|
||||
@Mock
|
||||
Context mContext;
|
||||
static final String PAYMENT_KEY = "nfc_payment";
|
||||
static final String FOREGROUND_KEY = "nfc_foreground";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@Mock
|
||||
private PackageManager mManager;
|
||||
|
||||
private PaymentSettings mFragment;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFragment = new PaymentSettings();
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mContext.getPackageManager()).thenReturn(mManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKey_NoNFC_KeyAdded() {
|
||||
public void getNonIndexableKey_NoNFC_AllKeysAdded() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(false);
|
||||
|
||||
final List<String> niks =
|
||||
PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
assertThat(niks).contains(PaymentSettings.PAYMENT_KEY);
|
||||
PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(niks).contains(PAYMENT_KEY);
|
||||
assertThat(niks).contains(FOREGROUND_KEY);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIndexableKey_NFC_NoKeyAdded() {
|
||||
public void getNonIndexableKey_NFC_ForegroundKeyAdded() {
|
||||
when(mManager.hasSystemFeature(PackageManager.FEATURE_NFC)).thenReturn(true);
|
||||
|
||||
final List<String> niks =
|
||||
PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
assertThat(niks).isEmpty();
|
||||
PaymentSettings.SEARCH_INDEX_DATA_PROVIDER.getNonIndexableKeys(mContext);
|
||||
|
||||
assertThat(niks).contains(FOREGROUND_KEY);
|
||||
}
|
||||
|
||||
@Implements(PaymentBackend.class)
|
||||
public static class ShadowPaymentBackend {
|
||||
private ArrayList<PaymentBackend.PaymentAppInfo> mAppInfos;
|
||||
|
||||
public void __constructor__(Context context) {
|
||||
mAppInfos = new ArrayList<>();
|
||||
mAppInfos.add(new PaymentBackend.PaymentAppInfo());
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public List<PaymentBackend.PaymentAppInfo> getPaymentAppInfos() {
|
||||
return mAppInfos;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user