OSDN Git Service

Handle disallowed NFC beam restriction
authorAmith Yamasani <yamasani@google.com>
Tue, 9 Sep 2014 19:07:11 +0000 (12:07 -0700)
committerAmith Yamasani <yamasani@google.com>
Tue, 9 Sep 2014 19:07:11 +0000 (12:07 -0700)
Don't enable the beam setting and toggle if it is disallowed for
the current user.

Bug: 17387303
Change-Id: Ifdfe049bef281454c978a37acb49c59758344ae6

src/com/android/settings/nfc/AndroidBeam.java
src/com/android/settings/nfc/NfcEnabler.java

index add0fa7..20201f4 100644 (file)
@@ -18,12 +18,15 @@ package com.android.settings.nfc;
 
 import android.app.ActionBar;
 import android.app.Fragment;
+import android.content.Context;
 import android.nfc.NfcAdapter;
 import android.os.Bundle;
+import android.os.UserManager;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Switch;
+
 import com.android.settings.R;
 import com.android.settings.SettingsActivity;
 import com.android.settings.widget.SwitchBar;
@@ -34,6 +37,7 @@ public class AndroidBeam extends Fragment
     private NfcAdapter mNfcAdapter;
     private SwitchBar mSwitchBar;
     private CharSequence mOldActivityTitle;
+    private boolean mBeamDisallowed;
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
@@ -45,6 +49,8 @@ public class AndroidBeam extends Fragment
         actionBar.setTitle(R.string.android_beam_settings_title);
 
         mNfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
+        mBeamDisallowed = ((UserManager) getActivity().getSystemService(Context.USER_SERVICE))
+                .hasUserRestriction(UserManager.DISALLOW_OUTGOING_BEAM);
     }
 
     @Override
@@ -62,8 +68,9 @@ public class AndroidBeam extends Fragment
         SettingsActivity activity = (SettingsActivity) getActivity();
 
         mSwitchBar = activity.getSwitchBar();
-        mSwitchBar.setChecked(mNfcAdapter.isNdefPushEnabled());
+        mSwitchBar.setChecked(!mBeamDisallowed && mNfcAdapter.isNdefPushEnabled());
         mSwitchBar.addOnSwitchChangeListener(this);
+        mSwitchBar.setEnabled(!mBeamDisallowed);
         mSwitchBar.show();
     }
 
index 2fb95e4..ae61b13 100644 (file)
@@ -21,10 +21,11 @@ import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.nfc.NfcAdapter;
+import android.os.UserManager;
 import android.preference.Preference;
 import android.preference.PreferenceScreen;
-
 import android.preference.SwitchPreference;
+
 import com.android.settings.R;
 
 /**
@@ -38,6 +39,7 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener {
     private final PreferenceScreen mAndroidBeam;
     private final NfcAdapter mNfcAdapter;
     private final IntentFilter mIntentFilter;
+    private boolean mBeamDisallowed;
 
     private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
         @Override
@@ -56,6 +58,8 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener {
         mSwitch = switchPreference;
         mAndroidBeam = androidBeam;
         mNfcAdapter = NfcAdapter.getDefaultAdapter(context);
+        mBeamDisallowed = ((UserManager) mContext.getSystemService(Context.USER_SERVICE))
+                .hasUserRestriction(UserManager.DISALLOW_OUTGOING_BEAM);
 
         if (mNfcAdapter == null) {
             // NFC is not supported
@@ -64,6 +68,9 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener {
             mIntentFilter = null;
             return;
         }
+        if (mBeamDisallowed) {
+            mAndroidBeam.setEnabled(false);
+        }
         mIntentFilter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
     }
 
@@ -110,8 +117,8 @@ public class NfcEnabler implements Preference.OnPreferenceChangeListener {
         case NfcAdapter.STATE_ON:
             mSwitch.setChecked(true);
             mSwitch.setEnabled(true);
-            mAndroidBeam.setEnabled(true);
-            if (mNfcAdapter.isNdefPushEnabled()) {
+            mAndroidBeam.setEnabled(!mBeamDisallowed);
+            if (mNfcAdapter.isNdefPushEnabled() && !mBeamDisallowed) {
                 mAndroidBeam.setSummary(R.string.android_beam_on_summary);
             } else {
                 mAndroidBeam.setSummary(R.string.android_beam_off_summary);