FileDocCategorySizeDatePackage
SecurityControllerImpl.javaAPI DocAndroid 5.1 API7258Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.policy

SecurityControllerImpl

public class SecurityControllerImpl extends Object implements SecurityController

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private static final android.net.NetworkRequest
REQUEST
private static final int
NO_NETWORK
private final android.content.Context
mContext
private final android.net.ConnectivityManager
mConnectivityManager
private final android.net.IConnectivityManager
mConnectivityService
private final android.app.admin.DevicePolicyManager
mDevicePolicyManager
private final ArrayList
mCallbacks
private com.android.internal.net.VpnConfig
mVpnConfig
private String
mVpnName
private int
mCurrentVpnNetworkId
private int
mCurrentUserId
private final android.net.ConnectivityManager.NetworkCallback
mNetworkCallback
Constructors Summary
public SecurityControllerImpl(android.content.Context context)


       
        mContext = context;
        mDevicePolicyManager = (DevicePolicyManager)
                context.getSystemService(Context.DEVICE_POLICY_SERVICE);
        mConnectivityManager = (ConnectivityManager)
                context.getSystemService(Context.CONNECTIVITY_SERVICE);

        // TODO: re-register network callback on user change.
        mConnectivityManager.registerNetworkCallback(REQUEST, mNetworkCallback);
        mCurrentUserId = ActivityManager.getCurrentUser();
    
Methods Summary
public voidaddCallback(SecurityControllerCallback callback)

        if (callback == null || mCallbacks.contains(callback)) return;
        if (DEBUG) Log.d(TAG, "addCallback " + callback);
        mCallbacks.add(callback);
    
public voiddisconnectFromVpn()

        try {
            if (isLegacyVpn()) {
                mConnectivityService.prepareVpn(VpnConfig.LEGACY_VPN, VpnConfig.LEGACY_VPN);
            } else {
                // Prevent this app from initiating VPN connections in the future without user
                // intervention.
                mConnectivityService.setVpnPackageAuthorization(false);

                mConnectivityService.prepareVpn(mVpnConfig.user, VpnConfig.LEGACY_VPN);
            }
        } catch (Exception e) {
            Log.e(TAG, "Unable to disconnect from VPN", e);
        }
    
public voiddump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)

        pw.println("SecurityController state:");
        pw.print("  mCurrentVpnNetworkId="); pw.println(mCurrentVpnNetworkId);
        pw.print("  mVpnConfig="); pw.println(mVpnConfig);
        pw.print("  mVpnName="); pw.println(mVpnName);
    
private voidfireCallbacks()

        for (SecurityControllerCallback callback : mCallbacks) {
            callback.onStateChanged();
        }
    
public java.lang.StringgetDeviceOwnerName()

        return mDevicePolicyManager.getDeviceOwnerName();
    
public java.lang.StringgetLegacyVpnName()

        return mVpnConfig.session;
    
public java.lang.StringgetProfileOwnerName()

        return mDevicePolicyManager.getProfileOwnerNameAsUser(mCurrentUserId);
    
public java.lang.StringgetVpnApp()

        return mVpnName;
    
public booleanhasDeviceOwner()

        return !TextUtils.isEmpty(mDevicePolicyManager.getDeviceOwner());
    
public booleanhasProfileOwner()

        return !TextUtils.isEmpty(mDevicePolicyManager.getProfileOwnerNameAsUser(mCurrentUserId));
    
public booleanisLegacyVpn()

        return mVpnConfig.legacy;
    
public booleanisVpnEnabled()

        return mCurrentVpnNetworkId != NO_NETWORK;
    
public voidonUserSwitched(int newUserId)

        mCurrentUserId = newUserId;
        fireCallbacks();
    
public voidremoveCallback(SecurityControllerCallback callback)

        if (callback == null) return;
        if (DEBUG) Log.d(TAG, "removeCallback " + callback);
        mCallbacks.remove(callback);
    
private voidsetCurrentNetid(int netId)

        if (netId != mCurrentVpnNetworkId) {
            mCurrentVpnNetworkId = netId;
            updateState();
            fireCallbacks();
        }
    
private voidupdateState()

        try {
            mVpnConfig = mConnectivityService.getVpnConfig();

            if (mVpnConfig != null && !mVpnConfig.legacy) {
                mVpnName = VpnConfig.getVpnLabel(mContext, mVpnConfig.user).toString();
            }
        } catch (RemoteException | NameNotFoundException e) {
            Log.w(TAG, "Unable to get current VPN", e);
        }