NFC support in work profile
Configure NFC payment settings based on userId. Bug: 202367033 Test: mauanl tests Change-Id: I97e275f374d34618b64188d5de185ec6c527e0fd
This commit is contained in:
@@ -21,12 +21,14 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.nfc.cardemulation.CardEmulation;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.app.AlertActivity;
|
||||
import com.android.internal.app.AlertController;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentAppInfo;
|
||||
import com.android.settings.nfc.PaymentBackend.PaymentInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -37,7 +39,7 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
private static final int PAYMENT_APP_MAX_CAPTION_LENGTH = 40;
|
||||
|
||||
private PaymentBackend mBackend;
|
||||
private ComponentName mNewDefault;
|
||||
private PaymentInfo mNewDefault;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -51,9 +53,10 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
ComponentName component = intent.getParcelableExtra(
|
||||
CardEmulation.EXTRA_SERVICE_COMPONENT);
|
||||
String category = intent.getStringExtra(CardEmulation.EXTRA_CATEGORY);
|
||||
int userId = intent.getIntExtra(CardEmulation.EXTRA_USERID, UserHandle.myUserId());
|
||||
|
||||
setResult(RESULT_CANCELED);
|
||||
if (!buildDialog(component, category)) {
|
||||
if (!buildDialog(component, category, userId)) {
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -63,7 +66,7 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case BUTTON_POSITIVE:
|
||||
mBackend.setDefaultPaymentApp(mNewDefault);
|
||||
mBackend.setDefaultPaymentApp(mNewDefault.componentName, mNewDefault.userId);
|
||||
setResult(RESULT_OK);
|
||||
break;
|
||||
case BUTTON_NEGATIVE:
|
||||
@@ -71,7 +74,7 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
}
|
||||
}
|
||||
|
||||
private boolean buildDialog(ComponentName component, String category) {
|
||||
private boolean buildDialog(ComponentName component, String category, int userId) {
|
||||
if (component == null || category == null) {
|
||||
Log.e(TAG, "Component or category are null");
|
||||
return false;
|
||||
@@ -88,10 +91,12 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
|
||||
List<PaymentAppInfo> services = mBackend.getPaymentAppInfos();
|
||||
for (PaymentAppInfo service : services) {
|
||||
if (component.equals(service.componentName)) {
|
||||
// check if userId matches
|
||||
if (component.equals(service.componentName)
|
||||
&& service.userHandle.getIdentifier() == userId) {
|
||||
requestedPaymentApp = service;
|
||||
}
|
||||
if (service.isDefault) {
|
||||
if (service.isDefault && service.userHandle.getIdentifier() == userId) {
|
||||
defaultPaymentApp = service;
|
||||
}
|
||||
}
|
||||
@@ -102,13 +107,17 @@ public final class PaymentDefaultDialog extends AlertActivity implements
|
||||
}
|
||||
|
||||
// Get current mode and default component
|
||||
ComponentName defaultComponent = mBackend.getDefaultPaymentApp();
|
||||
if (defaultComponent != null && defaultComponent.equals(component)) {
|
||||
PaymentInfo defaultComponent = mBackend.getDefaultPaymentApp();
|
||||
if (defaultComponent != null && defaultComponent.componentName.equals(component)
|
||||
&& defaultComponent.userId == userId) {
|
||||
Log.e(TAG, "Component " + component + " is already default.");
|
||||
return false;
|
||||
}
|
||||
|
||||
mNewDefault = component;
|
||||
mNewDefault = new PaymentInfo();
|
||||
mNewDefault.componentName = component;
|
||||
mNewDefault.userId = userId;
|
||||
|
||||
// Compose dialog; get
|
||||
final AlertController.AlertParams p = mAlertParams;
|
||||
if (defaultPaymentApp == null) {
|
||||
|
Reference in New Issue
Block a user