summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/android/nfc/BeamShareActivity.java3
-rwxr-xr-xsrc/com/android/nfc/NfcService.java54
2 files changed, 51 insertions, 6 deletions
diff --git a/src/com/android/nfc/BeamShareActivity.java b/src/com/android/nfc/BeamShareActivity.java
index 84a658a8..c22c184f 100644
--- a/src/com/android/nfc/BeamShareActivity.java
+++ b/src/com/android/nfc/BeamShareActivity.java
@@ -32,6 +32,7 @@ import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
import android.os.Bundle;
+import android.os.UserHandle;
import android.util.Log;
import android.webkit.URLUtil;
@@ -78,7 +79,7 @@ public class BeamShareActivity extends Activity {
private void showNfcDialogAndExit(int msgId) {
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
- registerReceiver(mReceiver, filter);
+ registerReceiverAsUser(mReceiver, UserHandle.ALL, filter, null, null);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this,
AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
diff --git a/src/com/android/nfc/NfcService.java b/src/com/android/nfc/NfcService.java
index d8278833..06bc06a3 100755
--- a/src/com/android/nfc/NfcService.java
+++ b/src/com/android/nfc/NfcService.java
@@ -20,6 +20,7 @@ import android.app.ActivityManager;
import android.app.Application;
import android.app.KeyguardManager;
import android.app.PendingIntent;
+import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
@@ -27,6 +28,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
@@ -372,6 +374,9 @@ public class NfcService implements DeviceHostListener {
ownerFilter.addDataScheme("package");
mContext.registerReceiver(mOwnerReceiver, ownerFilter);
+ IntentFilter policyFilter = new IntentFilter(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
+ mContext.registerReceiverAsUser(mPolicyReceiver, UserHandle.ALL, policyFilter, null, null);
+
updatePackageCache();
PackageManager pm = mContext.getPackageManager();
@@ -647,11 +652,39 @@ public class NfcService implements DeviceHostListener {
}
void setBeamShareActivityState(boolean enabled) {
- mContext.getPackageManager().setComponentEnabledSetting(
- new ComponentName("com.android.nfc","com.android.nfc.BeamShareActivity"),
- enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
- PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
- PackageManager.DONT_KILL_APP);
+ UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ // Propagate the state change to all user profiles related to the current
+ // user. Note that the list returned by getUserProfiles contains the
+ // current user.
+ List <UserHandle> luh = um.getUserProfiles();
+ for (UserHandle uh : luh){
+ enforceBeamShareActivityPolicy(mContext, uh, enabled);
+ }
+ }
+
+ void enforceBeamShareActivityPolicy(Context context, UserHandle uh,
+ boolean isGlobalEnabled){
+ UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ IPackageManager mIpm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
+ boolean isActiveForUser =
+ (!um.hasUserRestriction(UserManager.DISALLOW_OUTGOING_BEAM, uh)) &&
+ isGlobalEnabled;
+ if (DBG){
+ Log.d(TAG, "Enforcing a policy change on user: " + uh +
+ ", isActiveForUser = " + isActiveForUser);
+ }
+ try {
+ mIpm.setComponentEnabledSetting(new ComponentName(
+ BeamShareActivity.class.getPackageName$(),
+ BeamShareActivity.class.getName()),
+ isActiveForUser ?
+ PackageManager.COMPONENT_ENABLED_STATE_ENABLED :
+ PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+ PackageManager.DONT_KILL_APP,
+ uh.getIdentifier());
+ } catch (RemoteException e) {
+ Log.w(TAG, "Unable to change Beam status for user " + uh);
+ }
}
final class NfcAdapterService extends INfcAdapter.Stub {
@@ -1968,6 +2001,17 @@ public class NfcService implements DeviceHostListener {
}
};
+ private final BroadcastReceiver mPolicyReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent){
+ String action = intent.getAction();
+ if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED
+ .equals(action)) {
+ enforceBeamShareActivityPolicy(context,
+ new UserHandle(getSendingUserId()), mIsNdefPushEnabled);
+ }
+ }
+ };
/**
* Returns true if airplane mode is currently on