OSDN Git Service

Added a warning when the profile has an owner
authorSelim Cinek <cinek@google.com>
Wed, 27 Aug 2014 10:51:45 +0000 (12:51 +0200)
committerSelim Cinek <cinek@google.com>
Thu, 28 Aug 2014 13:09:28 +0000 (15:09 +0200)
Also fixed a bug where a post in the QSFooter
was not always on the mainthread leading to a
crash.

Bug: 17066115
Change-Id: Iea9e1032973058ed5e63e70da4dc0bcf34fa59a3

core/java/android/app/admin/DevicePolicyManager.java
packages/SystemUI/res/values/strings.xml
packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
packages/SystemUI/src/com/android/systemui/statusbar/phone/QSTileHost.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java

index 3f3da7d..69b1139 100644 (file)
@@ -2456,10 +2456,10 @@ public class DevicePolicyManager {
      * @throws IllegalArgumentException if the userId is invalid.
      */
     @SystemApi
-    public String getProfileOwnerNameAsUser(UserHandle user) throws IllegalArgumentException {
+    public String getProfileOwnerNameAsUser(int userId) throws IllegalArgumentException {
         if (mService != null) {
             try {
-                return mService.getProfileOwnerName(user.getIdentifier());
+                return mService.getProfileOwnerName(userId);
             } catch (RemoteException re) {
                 Log.w(TAG, "Failed to get profile owner");
                 throw new IllegalArgumentException(
index 0fe389a..189c052 100644 (file)
     <!-- Footer device owned text [CHAR LIMIT=50] -->
     <string name="device_owned_footer">Device may be monitored</string>
 
+    <!-- Footer profile owned text [CHAR LIMIT=50] -->
+    <string name="profile_owned_footer">Profile may be monitored</string>
+
     <!-- Footer vpn present text [CHAR LIMIT=50] -->
     <string name="vpn_footer">Network may be monitored</string>
 
     <!-- Monitoring dialog title for device owned devices [CHAR LIMIT=35] -->
     <string name="monitoring_title_device_owned">Device monitoring</string>
 
+    <!-- Monitoring dialog title for profile owned devices [CHAR LIMIT=35] -->
+    <string name="monitoring_title_profile_owned">Profile monitoring</string>
+
     <!-- Monitoring dialog title for normal devices  [CHAR LIMIT=35]-->
     <string name="monitoring_title">Network monitoring</string>
 
     <!-- Monitoring dialog legacy VPN with device owner text [CHAR LIMIT=300] -->
     <string name="monitoring_description_legacy_vpn_device_owned">This device is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\n\nYour administrator is capable of monitoring your network activity including emails, apps, and secure websites. For more information, contact your administrator.\n\nAlso, you\'re connected to a VPN (\"<xliff:g id="application">%2$s</xliff:g>\"). Your VPN service provider can monitor network activity too.</string>
 
+    <!-- Monitoring dialog profile owner body text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_profile_owned">This profile is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\n\nYour administrator can monitor your device and network activity, including emails, apps and secure websites.\n\nFor more information, contact your administrator.</string>
+
+    <!-- Monitoring dialog device and profile owner body text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_device_and_profile_owned">This device is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\nYour profile is managed by:\n<xliff:g id="organization">%2$s</xliff:g>\n\nYour administrator can monitor your device and network activity, including emails, apps and secure websites.\n\nFor more information, contact your administrator.</string>
+
+    <!-- Monitoring dialog non-legacy VPN with profile owner text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_vpn_profile_owned">This profile is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\n\nYour administrator is capable of monitoring your network activity including emails, apps, and secure websites. For more information, contact your administrator.\n\nAlso, you gave \"<xliff:g id="application">%2$s</xliff:g>\" permission to set up a VPN connection. This app can monitor network activity too.</string>
+
+    <!-- Monitoring dialog legacy VPN with profile owner text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_legacy_vpn_profile_owned">This profile is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\n\nYour administrator is capable of monitoring your network activity including emails, apps, and secure websites. For more information, contact your administrator.\n\nAlso, you\'re connected to a VPN (\"<xliff:g id="application">%2$s</xliff:g>\"). Your VPN service provider can monitor network activity too.</string>
+
+    <!-- Monitoring dialog non-legacy VPN with device and profile owner text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_vpn_device_and_profile_owned">This device is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\nYour profile is managed by:\n<xliff:g id="organization">%2$s</xliff:g>\n\nYour administrator is capable of monitoring your network activity including emails, apps, and secure websites. For more information, contact your administrator.\n\nAlso, you gave \"<xliff:g id="application">%3$s</xliff:g>\" permission to set up a VPN connection. This app can monitor network activity too.</string>
+
+    <!-- Monitoring dialog legacy VPN with device and profile owner text [CHAR LIMIT=300] -->
+    <string name="monitoring_description_legacy_vpn_device_and_profile_owned">This device is managed by:\n<xliff:g id="organization">%1$s</xliff:g>\nYour profile is managed by:\n<xliff:g id="organization">%2$s</xliff:g>\n\nYour administrator is capable of monitoring your network activity including emails, apps, and secure websites. For more information, contact your administrator.\n\nAlso, you\'re connected to a VPN (\"<xliff:g id="application">%3$s</xliff:g>\"). Your VPN service provider can monitor network activity too.</string>
+
     <!-- Indication on the keyguard that appears when the user disables trust agents until the next time they unlock manually. [CHAR LIMIT=NONE] -->
     <string name="keyguard_indication_trust_disabled">Device will stay locked until you manually unlock</string>
 
index 82e6df2..a0b6e82 100644 (file)
@@ -24,11 +24,9 @@ import android.os.Looper;
 import android.os.Message;
 import android.util.Log;
 import android.util.TypedValue;
-import android.view.ContextThemeWrapper;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.view.WindowManager;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -37,7 +35,6 @@ import com.android.systemui.R;
 import com.android.systemui.statusbar.phone.QSTileHost;
 import com.android.systemui.statusbar.phone.SystemUIDialog;
 import com.android.systemui.statusbar.policy.SecurityController;
-import com.android.systemui.statusbar.policy.SecurityController.VpnCallback;
 
 public class QSFooter implements OnClickListener, DialogInterface.OnClickListener {
     protected static final String TAG = "QSFooter";
@@ -53,6 +50,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
     private AlertDialog mDialog;
     private QSTileHost mHost;
     private Handler mHandler;
+    private final Handler mMainHandler;
 
     private boolean mIsVisible;
     private boolean mIsIconVisible;
@@ -65,6 +63,7 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
         mFooterText = (TextView) mRootView.findViewById(R.id.footer_text);
         mFooterIcon = (ImageView) mRootView.findViewById(R.id.footer_icon);
         mContext = context;
+        mMainHandler = new Handler();
     }
 
     public void setHost(QSTileHost host) {
@@ -113,14 +112,19 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
             mFooterTextId = R.string.device_owned_footer;
             mIsVisible = true;
             mIsIconVisible = false;
+        } else if (mSecurityController.hasProfileOwner()) {
+            mFooterTextId = R.string.profile_owned_footer;
+            mIsVisible = true;
+            mIsIconVisible = false;
         } else if (mSecurityController.isVpnEnabled()) {
             mFooterTextId = R.string.vpn_footer;
             mIsVisible = true;
             mIsIconVisible = true;
         } else {
             mIsVisible = false;
+            mIsIconVisible = false;
         }
-        mRootView.post(mUpdateDisplayState);
+        mMainHandler.post(mUpdateDisplayState);
     }
 
     @Override
@@ -155,20 +159,61 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
 
     private String getMessage() {
         if (mSecurityController.hasDeviceOwner()) {
+            if (mSecurityController.hasProfileOwner()) {
+                if (mSecurityController.isVpnEnabled()) {
+                    if (mSecurityController.isLegacyVpn()) {
+                        return mContext.getString(
+                                R.string.monitoring_description_legacy_vpn_device_and_profile_owned,
+                                mSecurityController.getDeviceOwnerName(),
+                                mSecurityController.getProfileOwnerName(),
+                                mSecurityController.getLegacyVpnName());
+                    } else {
+                        return mContext.getString(
+                                R.string.monitoring_description_vpn_device_and_profile_owned,
+                                mSecurityController.getDeviceOwnerName(),
+                                mSecurityController.getProfileOwnerName(),
+                                mSecurityController.getVpnApp());
+                    }
+                } else {
+                    return mContext.getString(
+                            R.string.monitoring_description_device_and_profile_owned,
+                            mSecurityController.getDeviceOwnerName(),
+                            mSecurityController.getProfileOwnerName());
+                }
+            } else {
+                if (mSecurityController.isVpnEnabled()) {
+                    if (mSecurityController.isLegacyVpn()) {
+                        return mContext.getString(
+                                R.string.monitoring_description_legacy_vpn_device_owned,
+                                mSecurityController.getDeviceOwnerName(),
+                                mSecurityController.getLegacyVpnName());
+                    } else {
+                        return mContext.getString(R.string.monitoring_description_vpn_device_owned,
+                                mSecurityController.getDeviceOwnerName(),
+                                mSecurityController.getVpnApp());
+                    }
+                } else {
+                    return mContext.getString(R.string.monitoring_description_device_owned,
+                            mSecurityController.getDeviceOwnerName());
+                }
+            }
+        } else if (mSecurityController.hasProfileOwner()) {
             if (mSecurityController.isVpnEnabled()) {
                 if (mSecurityController.isLegacyVpn()) {
                     return mContext.getString(
-                            R.string.monitoring_description_legacy_vpn_device_owned,
-                            mSecurityController.getDeviceOwnerName(),
+                            R.string.monitoring_description_legacy_vpn_profile_owned,
+                            mSecurityController.getProfileOwnerName(),
                             mSecurityController.getLegacyVpnName());
                 } else {
-                    return mContext.getString(R.string.monitoring_description_vpn_device_owned,
-                            mSecurityController.getDeviceOwnerName(),
+                    return mContext.getString(
+                            R.string.monitoring_description_vpn_profile_owned,
+                            mSecurityController.getProfileOwnerName(),
                             mSecurityController.getVpnApp());
                 }
             } else {
-                return mContext.getString(R.string.monitoring_description_device_owned,
-                        mSecurityController.getDeviceOwnerName());
+                return mContext.getString(
+                        R.string.monitoring_description_profile_owned,
+                        mSecurityController.getProfileOwnerName());
             }
         } else {
             if (mSecurityController.isLegacyVpn()) {
@@ -186,6 +231,9 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
         if (mSecurityController.hasDeviceOwner()) {
             return R.string.monitoring_title_device_owned;
         }
+        if (mSecurityController.hasProfileOwner()) {
+            return R.string.monitoring_title_profile_owned;
+        }
         return R.string.monitoring_title;
     }
 
@@ -200,9 +248,9 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
         }
     };
 
-    private class Callback implements VpnCallback {
+    private class Callback implements SecurityController.SecurityControllerCallback {
         @Override
-        public void onVpnStateChanged() {
+        public void onStateChanged() {
             refreshState();
         }
     }
index 729d459..2dc08d4 100644 (file)
@@ -119,6 +119,7 @@ public class QSTileHost implements QSTile.Host {
                 for (QSTile<?> tile : mTiles.values()) {
                     tile.userSwitch(newUserId);
                 }
+                mSecurity.onUserSwitched(newUserId);
                 mObserver.register();
             }
         };
index 3a5a53b..6148feb 100644 (file)
@@ -18,18 +18,21 @@ package com.android.systemui.statusbar.policy;
 public interface SecurityController {
 
     boolean hasDeviceOwner();
+    boolean hasProfileOwner();
     String getDeviceOwnerName();
+    String getProfileOwnerName();
     boolean isVpnEnabled();
     String getVpnApp();
     boolean isLegacyVpn();
     String getLegacyVpnName();
     void disconnectFromVpn();
+    void onUserSwitched(int newUserId);
 
-    void addCallback(VpnCallback callback);
-    void removeCallback(VpnCallback callback);
+    void addCallback(SecurityControllerCallback callback);
+    void removeCallback(SecurityControllerCallback callback);
 
-    public interface VpnCallback {
-        void onVpnStateChanged();
+    public interface SecurityControllerCallback {
+        void onStateChanged();
     }
 
 }
index 499fe0b..a15ddaf 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.android.systemui.statusbar.policy;
 
+import android.app.ActivityManager;
 import android.app.admin.DevicePolicyManager;
 import android.content.Context;
 import android.content.pm.PackageManager.NameNotFoundException;
@@ -52,11 +53,13 @@ public class SecurityControllerImpl implements SecurityController {
     private final IConnectivityManager mConnectivityService = IConnectivityManager.Stub.asInterface(
                 ServiceManager.getService(Context.CONNECTIVITY_SERVICE));
     private final DevicePolicyManager mDevicePolicyManager;
-    private final ArrayList<VpnCallback> mCallbacks = new ArrayList<VpnCallback>();
+    private final ArrayList<SecurityControllerCallback> mCallbacks
+            = new ArrayList<SecurityControllerCallback>();
 
     private VpnConfig mVpnConfig;
     private String mVpnName;
     private int mCurrentVpnNetworkId = NO_NETWORK;
+    private int mCurrentUserId;
 
     public SecurityControllerImpl(Context context) {
         mContext = context;
@@ -67,6 +70,7 @@ public class SecurityControllerImpl implements SecurityController {
 
         // TODO: re-register network callback on user change.
         mConnectivityManager.registerNetworkCallback(REQUEST, mNetworkCallback);
+        mCurrentUserId = ActivityManager.getCurrentUser();
     }
 
     public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
@@ -82,11 +86,22 @@ public class SecurityControllerImpl implements SecurityController {
     }
 
     @Override
+    public boolean hasProfileOwner() {
+        return !TextUtils.isEmpty(mDevicePolicyManager.getProfileOwnerNameAsUser(mCurrentUserId));
+    }
+
+    @Override
     public String getDeviceOwnerName() {
         return mDevicePolicyManager.getDeviceOwnerName();
     }
 
     @Override
+    public String getProfileOwnerName() {
+        return mDevicePolicyManager.getProfileOwnerNameAsUser(mCurrentUserId);
+    }
+
+
+    @Override
     public boolean isVpnEnabled() {
         return mCurrentVpnNetworkId != NO_NETWORK;
     }
@@ -124,19 +139,25 @@ public class SecurityControllerImpl implements SecurityController {
     }
 
     @Override
-    public void addCallback(VpnCallback callback) {
+    public void addCallback(SecurityControllerCallback callback) {
         if (callback == null) return;
         if (DEBUG) Log.d(TAG, "removeCallback " + callback);
         mCallbacks.remove(callback);
     }
 
     @Override
-    public void removeCallback(VpnCallback callback) {
+    public void removeCallback(SecurityControllerCallback callback) {
         if (callback == null || mCallbacks.contains(callback)) return;
         if (DEBUG) Log.d(TAG, "addCallback " + callback);
         mCallbacks.add(callback);
     }
 
+    @Override
+    public void onUserSwitched(int newUserId) {
+        mCurrentUserId = newUserId;
+        fireCallbacks();
+    }
+
     private void setCurrentNetid(int netId) {
         if (netId != mCurrentVpnNetworkId) {
             mCurrentVpnNetworkId = netId;
@@ -146,8 +167,8 @@ public class SecurityControllerImpl implements SecurityController {
     }
 
     private void fireCallbacks() {
-        for (VpnCallback callback : mCallbacks) {
-            callback.onVpnStateChanged();
+        for (SecurityControllerCallback callback : mCallbacks) {
+            callback.onStateChanged();
         }
     }