summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/SystemUI/src')
-rw-r--r--packages/SystemUI/src/com/android/systemui/assist/AssistManager.java85
-rw-r--r--packages/SystemUI/src/com/android/systemui/qs/QSFooter.java67
-rw-r--r--packages/SystemUI/src/com/android/systemui/recents/Recents.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java95
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java1
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java2
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java83
-rw-r--r--packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java10
9 files changed, 253 insertions, 103 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
index f129288..3e122da 100644
--- a/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
+++ b/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
@@ -9,14 +9,15 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Resources;
+import android.database.ContentObserver;
import android.graphics.PixelFormat;
import android.media.AudioAttributes;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Handler;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
-import android.os.Vibrator;
import android.provider.Settings;
import android.util.Log;
import android.view.Gravity;
@@ -56,6 +57,8 @@ public class AssistManager {
private final PhoneStatusBar mBar;
private final IVoiceInteractionManagerService mVoiceInteractionManagerService;
+ private ComponentName mAssistComponent;
+
private IVoiceInteractionSessionShowCallback mShowCallback =
new IVoiceInteractionSessionShowCallback.Stub() {
@@ -78,12 +81,24 @@ public class AssistManager {
}
};
+ private final ContentObserver mAssistSettingsObserver = new ContentObserver(new Handler()) {
+ @Override
+ public void onChange(boolean selfChange) {
+ updateAssistInfo();
+ }
+ };
+
public AssistManager(PhoneStatusBar bar, Context context) {
mContext = context;
mBar = bar;
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
mVoiceInteractionManagerService = IVoiceInteractionManagerService.Stub.asInterface(
ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
+
+ mContext.getContentResolver().registerContentObserver(
+ Settings.Secure.getUriFor(Settings.Secure.ASSISTANT), false,
+ mAssistSettingsObserver);
+ mAssistSettingsObserver.onChange(false);
}
public void onConfigurationChanged() {
@@ -108,16 +123,17 @@ public class AssistManager {
}
public void onGestureInvoked(boolean vibrate) {
- boolean isVoiceInteractorActive = getVoiceInteractorSupportsAssistGesture();
- if (!isVoiceInteractorActive && !isAssistantIntentAvailable()) {
+ if (mAssistComponent == null) {
return;
}
+
if (vibrate) {
vibrate();
}
- if (!isVoiceInteractorActive || !isVoiceSessionRunning()) {
+ final boolean isService = isAssistantService();
+ if (isService || !isVoiceSessionRunning()) {
showOrb();
- mView.postDelayed(mHideRunnable, isVoiceInteractorActive
+ mView.postDelayed(mHideRunnable, isService
? TIMEOUT_SERVICE
: TIMEOUT_ACTIVITY);
}
@@ -157,10 +173,12 @@ public class AssistManager {
}
private void startAssist() {
- if (getVoiceInteractorSupportsAssistGesture()) {
- startVoiceInteractor();
- } else {
- startAssistActivity();
+ if (mAssistComponent != null) {
+ if (isAssistantService()) {
+ startVoiceInteractor();
+ } else {
+ startAssistActivity();
+ }
}
}
@@ -178,6 +196,9 @@ public class AssistManager {
if (intent == null) {
return;
}
+ if (mAssistComponent != null) {
+ intent.setComponent(mAssistComponent);
+ }
try {
final ActivityOptions opts = ActivityOptions.makeCustomAnimation(mContext,
@@ -255,19 +276,9 @@ public class AssistManager {
}
private void maybeSwapSearchIcon() {
- Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .getAssistIntent(mContext, false, UserHandle.USER_CURRENT);
- ComponentName component = null;
- boolean isService = false;
- if (getVoiceInteractorSupportsAssistGesture()) {
- component = getVoiceInteractorComponentName();
- isService = true;
- } else if (intent != null) {
- component = intent.getComponent();
- }
- if (component != null) {
- replaceDrawable(mView.getOrb().getLogo(), component, ASSIST_ICON_METADATA_NAME,
- isService);
+ if (mAssistComponent != null) {
+ replaceDrawable(mView.getOrb().getLogo(), mAssistComponent, ASSIST_ICON_METADATA_NAME,
+ isAssistantService());
} else {
mView.getOrb().getLogo().setImageDrawable(null);
}
@@ -308,8 +319,32 @@ public class AssistManager {
mView.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
}
- public boolean isAssistantIntentAvailable() {
- return ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
- .getAssistIntent(mContext, false, UserHandle.USER_CURRENT) != null;
+ private boolean isAssistantService() {
+ return mAssistComponent == null ?
+ false : mAssistComponent.equals(getVoiceInteractorComponentName());
+ }
+
+ private void updateAssistInfo() {
+ final String setting = Settings.Secure.getStringForUser(mContext.getContentResolver(),
+ Settings.Secure.ASSISTANT, UserHandle.USER_CURRENT);
+ if (setting != null) {
+ mAssistComponent = ComponentName.unflattenFromString(setting);
+ return;
+ }
+
+ // Fallback to keep backward compatible behavior when there is no user setting.
+ if (getVoiceInteractorSupportsAssistGesture()) {
+ mAssistComponent = getVoiceInteractorComponentName();
+ return;
+ }
+
+ Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
+ .getAssistIntent(mContext, false, UserHandle.USER_CURRENT);
+ if (intent != null) {
+ mAssistComponent = intent.getComponent();
+ return;
+ }
+
+ mAssistComponent = null;
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
index f59e864..ca38528 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
@@ -110,15 +110,13 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
}
private void handleRefreshState() {
- boolean hasDeviceOwner = mSecurityController.hasDeviceOwner();
- boolean hasVpn = mSecurityController.isVpnEnabled();
-
- mIsVisible = (hasVpn || hasDeviceOwner);
- mIsIconVisible = hasVpn;
- if (hasDeviceOwner) {
+ mIsIconVisible = mSecurityController.isVpnEnabled();
+ if (mSecurityController.hasDeviceOwner()) {
mFooterTextId = R.string.device_owned_footer;
+ mIsVisible = true;
} else {
mFooterTextId = R.string.vpn_footer;
+ mIsVisible = mIsIconVisible;
}
mMainHandler.post(mUpdateDisplayState);
}
@@ -132,15 +130,17 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
}
private void createDialog() {
- boolean hasDeviceOwner = mSecurityController.hasDeviceOwner();
- boolean hasProfile = mSecurityController.hasProfileOwner();
- boolean hasVpn = mSecurityController.isVpnEnabled();
+ String deviceOwner = mSecurityController.getDeviceOwnerName();
+ String profileOwner = mSecurityController.getProfileOwnerName();
+ String primaryVpn = mSecurityController.getPrimaryVpnName();
+ String profileVpn = mSecurityController.getProfileVpnName();
+ boolean managed = mSecurityController.hasProfileOwner();
mDialog = new SystemUIDialog(mContext);
- mDialog.setTitle(getTitle(hasDeviceOwner, hasProfile));
- mDialog.setMessage(getMessage(hasDeviceOwner, hasProfile, hasVpn));
+ mDialog.setTitle(getTitle(deviceOwner));
+ mDialog.setMessage(getMessage(deviceOwner, profileOwner, primaryVpn, profileVpn, managed));
mDialog.setButton(DialogInterface.BUTTON_POSITIVE, getPositiveButton(), this);
- if (hasVpn) {
+ if (mSecurityController.isVpnEnabled()) {
mDialog.setButton(DialogInterface.BUTTON_NEGATIVE, getNegativeButton(), this);
}
mDialog.show();
@@ -154,31 +154,42 @@ public class QSFooter implements OnClickListener, DialogInterface.OnClickListene
return mContext.getString(R.string.quick_settings_done);
}
- private String getMessage(boolean hasDeviceOwner, boolean hasProfile, boolean hasVpn) {
- if (hasDeviceOwner) {
- if (hasVpn) {
- return mContext.getString(R.string.monitoring_description_vpn_device_owned,
- mSecurityController.getDeviceOwnerName());
+ private String getMessage(String deviceOwner, String profileOwner, String primaryVpn,
+ String profileVpn, boolean primaryUserIsManaged) {
+ if (deviceOwner != null) {
+ if (primaryVpn != null) {
+ return mContext.getString(R.string.monitoring_description_vpn_app_device_owned,
+ deviceOwner, primaryVpn);
} else {
return mContext.getString(R.string.monitoring_description_device_owned,
- mSecurityController.getDeviceOwnerName());
+ deviceOwner);
+ }
+ } else if (primaryVpn != null) {
+ if (profileVpn != null) {
+ return mContext.getString(R.string.monitoring_description_app_personal_work,
+ profileOwner, profileVpn, primaryVpn);
+ } else {
+ return mContext.getString(R.string.monitoring_description_app_personal,
+ primaryVpn);
}
- } else if (hasProfile) {
- return mContext.getString(
- R.string.monitoring_description_vpn_profile_owned,
- mSecurityController.getProfileOwnerName());
+ } else if (profileVpn != null) {
+ return mContext.getString(R.string.monitoring_description_app_work,
+ profileOwner, profileVpn);
+ } else if (profileOwner != null && primaryUserIsManaged) {
+ return mContext.getString(R.string.monitoring_description_device_owned,
+ profileOwner);
} else {
- return mContext.getString(R.string.monitoring_description_vpn);
+ // No device owner, no personal VPN, no work VPN, no user owner. Why are we here?
+ return null;
}
}
- private int getTitle(boolean hasDeviceOwner, boolean hasProfile) {
- if (hasDeviceOwner) {
+ private int getTitle(String deviceOwner) {
+ if (deviceOwner != null) {
return R.string.monitoring_title_device_owned;
- } else if (hasProfile) {
- return R.string.monitoring_title_profile_owned;
+ } else {
+ return R.string.monitoring_title;
}
- return R.string.monitoring_title;
}
private final Runnable mUpdateDisplayState = new Runnable() {
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
index 7d2b5c87..442af90 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
@@ -365,7 +365,7 @@ public class Recents extends SystemUI
void preloadRecentsInternal() {
// Preload only the raw task list into a new load plan (which will be consumed by the
- // RecentsActivity)
+ // RecentsActivity) only if there is a task to animate to.
ActivityManager.RunningTaskInfo topTask = mSystemServicesProxy.getTopMostTask();
MutableBoolean topTaskHome = new MutableBoolean(true);
RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
@@ -374,8 +374,10 @@ public class Recents extends SystemUI
sInstanceLoadPlan.preloadRawTasks(topTaskHome.value);
loader.preloadTasks(sInstanceLoadPlan, topTaskHome.value);
TaskStack top = sInstanceLoadPlan.getAllTaskStacks().get(0);
- preCacheThumbnailTransitionBitmapAsync(topTask, top, mDummyStackView,
- topTaskHome.value);
+ if (top.getTaskCount() > 0) {
+ preCacheThumbnailTransitionBitmapAsync(topTask, top, mDummyStackView,
+ topTaskHome.value);
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java
index 13b3898..b93fc76 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java
@@ -34,6 +34,7 @@ import com.android.systemui.R;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
import com.android.systemui.statusbar.policy.UserInfoController;
+import com.android.systemui.statusbar.policy.UserSwitcherController;
import java.text.NumberFormat;
@@ -140,6 +141,10 @@ public class KeyguardStatusBarView extends RelativeLayout
((BatteryMeterView) findViewById(R.id.battery)).setBatteryController(batteryController);
}
+ public void setUserSwitcherController(UserSwitcherController controller) {
+ mMultiUserSwitch.setUserSwitcherController(controller);
+ }
+
public void setUserInfoController(UserInfoController userInfoController) {
userInfoController.addListener(new UserInfoController.OnUserInfoChangedListener() {
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
index f11d83c..e70d146 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/MultiUserSwitch.java
@@ -24,7 +24,7 @@ import android.provider.ContactsContract;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
-import android.view.accessibility.AccessibilityEvent;
+import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.android.systemui.R;
@@ -40,10 +40,14 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
private QSPanel mQsPanel;
private KeyguardUserSwitcher mKeyguardUserSwitcher;
private boolean mKeyguardMode;
+ private UserSwitcherController.BaseUserAdapter mUserListener;
+
final UserManager mUserManager;
private final int[] mTmpInt2 = new int[2];
+ private UserSwitcherController mUserSwitcherController;
+
public MultiUserSwitch(Context context, AttributeSet attrs) {
super(context, attrs);
mUserManager = UserManager.get(getContext());
@@ -53,10 +57,18 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
protected void onFinishInflate() {
super.onFinishInflate();
setOnClickListener(this);
+ refreshContentDescription();
}
public void setQsPanel(QSPanel qsPanel) {
mQsPanel = qsPanel;
+ setUserSwitcherController(qsPanel.getHost().getUserSwitcherController());
+ }
+
+ public void setUserSwitcherController(UserSwitcherController userSwitcherController) {
+ mUserSwitcherController = userSwitcherController;
+ registerListener();
+ refreshContentDescription();
}
public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) {
@@ -65,6 +77,28 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
public void setKeyguardMode(boolean keyguardShowing) {
mKeyguardMode = keyguardShowing;
+ registerListener();
+ }
+
+ private void registerListener() {
+ if (UserSwitcherController.isUserSwitcherAvailable(mUserManager) && mUserListener == null) {
+
+ final UserSwitcherController controller = mUserSwitcherController;
+ if (controller != null) {
+ mUserListener = new UserSwitcherController.BaseUserAdapter(controller) {
+ @Override
+ public void notifyDataSetChanged() {
+ refreshContentDescription();
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ return null;
+ }
+ };
+ refreshContentDescription();
+ }
+ }
}
@Override
@@ -74,22 +108,16 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
if (mKeyguardUserSwitcher != null) {
mKeyguardUserSwitcher.show(true /* animate */);
}
- } else {
- if (mQsPanel != null) {
- UserSwitcherController userSwitcherController =
- mQsPanel.getHost().getUserSwitcherController();
- if (userSwitcherController != null) {
- View center = getChildCount() > 0 ? getChildAt(0) : this;
-
- center.getLocationInWindow(mTmpInt2);
- mTmpInt2[0] += center.getWidth() / 2;
- mTmpInt2[1] += center.getHeight() / 2;
-
- mQsPanel.showDetailAdapter(true,
- userSwitcherController.userDetailAdapter,
- mTmpInt2);
- }
- }
+ } else if (mQsPanel != null && mUserSwitcherController != null) {
+ View center = getChildCount() > 0 ? getChildAt(0) : this;
+
+ center.getLocationInWindow(mTmpInt2);
+ mTmpInt2[0] += center.getWidth() / 2;
+ mTmpInt2[1] += center.getHeight() / 2;
+
+ mQsPanel.showDetailAdapter(true,
+ mUserSwitcherController.userDetailAdapter,
+ mTmpInt2);
}
} else {
Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
@@ -100,20 +128,21 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
}
@Override
- public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
- super.onPopulateAccessibilityEvent(event);
+ public void setClickable(boolean clickable) {
+ super.setClickable(clickable);
+ refreshContentDescription();
+ }
+ private void refreshContentDescription() {
+ String currentUser = null;
+ if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)
+ && mUserSwitcherController != null) {
+ currentUser = mUserSwitcherController.getCurrentUserName(mContext);
+ }
+
+ String text = null;
if (isClickable()) {
- String text;
if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
- String currentUser = null;
- if (mQsPanel != null) {
- UserSwitcherController controller = mQsPanel.getHost()
- .getUserSwitcherController();
- if (controller != null) {
- currentUser = controller.getCurrentUserName(mContext);
- }
- }
if (TextUtils.isEmpty(currentUser)) {
text = mContext.getString(R.string.accessibility_multi_user_switch_switcher);
} else {
@@ -124,11 +153,17 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
} else {
text = mContext.getString(R.string.accessibility_multi_user_switch_quick_contact);
}
- if (!TextUtils.isEmpty(text)) {
- event.getText().add(text);
+ } else {
+ if (!TextUtils.isEmpty(currentUser)) {
+ text = mContext.getString(
+ R.string.accessibility_multi_user_switch_inactive,
+ currentUser);
}
}
+ if (!TextUtils.equals(getContentDescription(), text)) {
+ setContentDescription(text);
+ }
}
@Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
index aa5aba0..a5b18f9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java
@@ -860,6 +860,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
// User info. Trigger first load.
mHeader.setUserInfoController(mUserInfoController);
mKeyguardStatusBar.setUserInfoController(mUserInfoController);
+ mKeyguardStatusBar.setUserSwitcherController(mUserSwitcherController);
mUserInfoController.reloadUserInfo();
mHeader.setBatteryController(mBatteryController);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
index e1e022d..40984d4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityController.java
@@ -22,6 +22,8 @@ public interface SecurityController {
String getDeviceOwnerName();
String getProfileOwnerName();
boolean isVpnEnabled();
+ String getPrimaryVpnName();
+ String getProfileVpnName();
void onUserSwitched(int newUserId);
void addCallback(SecurityControllerCallback callback);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
index 4f47cc6..962000a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SecurityControllerImpl.java
@@ -36,6 +36,7 @@ import android.util.SparseArray;
import com.android.internal.net.VpnConfig;
import com.android.internal.net.VpnInfo;
+import com.android.systemui.R;
import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -61,7 +62,7 @@ public class SecurityControllerImpl implements SecurityController {
private final ArrayList<SecurityControllerCallback> mCallbacks
= new ArrayList<SecurityControllerCallback>();
- private SparseArray<Boolean> mCurrentVpnUsers = new SparseArray<>();
+ private SparseArray<VpnConfig> mCurrentVpns = new SparseArray<>();
private int mCurrentUserId;
public SecurityControllerImpl(Context context) {
@@ -82,7 +83,16 @@ public class SecurityControllerImpl implements SecurityController {
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("SecurityController state:");
- pw.print(" mCurrentVpnUsers=" + mCurrentVpnUsers);
+ pw.print(" mCurrentVpns={");
+ for (int i = 0 ; i < mCurrentVpns.size(); i++) {
+ if (i > 0) {
+ pw.print(", ");
+ }
+ pw.print(mCurrentVpns.keyAt(i));
+ pw.print('=');
+ pw.print(mCurrentVpns.valueAt(i).user);
+ }
+ pw.println("}");
}
@Override
@@ -97,11 +107,7 @@ public class SecurityControllerImpl implements SecurityController {
@Override
public boolean hasProfileOwner() {
- boolean result = false;
- for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
- result |= (mDevicePolicyManager.getProfileOwnerAsUser(profile.id) != null);
- }
- return result;
+ return mDevicePolicyManager.getProfileOwnerAsUser(mCurrentUserId) != null;
}
@Override
@@ -116,8 +122,37 @@ public class SecurityControllerImpl implements SecurityController {
}
@Override
+ public String getPrimaryVpnName() {
+ VpnConfig cfg = mCurrentVpns.get(mCurrentUserId);
+ if (cfg != null) {
+ return getNameForVpnConfig(cfg, new UserHandle(mCurrentUserId));
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public String getProfileVpnName() {
+ for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
+ if (profile.id == mCurrentUserId) {
+ continue;
+ }
+ VpnConfig cfg = mCurrentVpns.get(profile.id);
+ if (cfg != null) {
+ return getNameForVpnConfig(cfg, profile.getUserHandle());
+ }
+ }
+ return null;
+ }
+
+ @Override
public boolean isVpnEnabled() {
- return mCurrentVpnUsers.get(mCurrentUserId) != null;
+ for (UserInfo profile : mUserManager.getProfiles(mCurrentUserId)) {
+ if (mCurrentVpns.get(profile.id) != null) {
+ return true;
+ }
+ }
+ return false;
}
@Override
@@ -140,6 +175,22 @@ public class SecurityControllerImpl implements SecurityController {
fireCallbacks();
}
+ private String getNameForVpnConfig(VpnConfig cfg, UserHandle user) {
+ if (cfg.legacy) {
+ return mContext.getString(R.string.legacy_vpn_name);
+ }
+ // The package name for an active VPN is stored in the 'user' field of its VpnConfig
+ final String vpnPackage = cfg.user;
+ try {
+ Context userContext = mContext.createPackageContextAsUser(mContext.getPackageName(),
+ 0 /* flags */, user);
+ return VpnConfig.getVpnLabel(userContext, vpnPackage).toString();
+ } catch (NameNotFoundException nnfe) {
+ Log.e(TAG, "Package " + vpnPackage + " is not present", nnfe);
+ return null;
+ }
+ }
+
private void fireCallbacks() {
for (SecurityControllerCallback callback : mCallbacks) {
callback.onStateChanged();
@@ -148,21 +199,20 @@ public class SecurityControllerImpl implements SecurityController {
private void updateState() {
// Find all users with an active VPN
- SparseArray<Boolean> vpnUsers = new SparseArray<>();
+ SparseArray<VpnConfig> vpns = new SparseArray<>();
try {
- for (VpnInfo vpn : mConnectivityManagerService.getAllVpnInfo()) {
- UserInfo user = mUserManager.getUserInfo(UserHandle.getUserId(vpn.ownerUid));
- int groupId = (user.profileGroupId != UserInfo.NO_PROFILE_GROUP_ID ?
- user.profileGroupId : user.id);
-
- vpnUsers.put(groupId, Boolean.TRUE);
+ for (UserInfo user : mUserManager.getUsers()) {
+ VpnConfig cfg = mConnectivityManagerService.getVpnConfig(user.id);
+ if (cfg != null) {
+ vpns.put(user.id, cfg);
+ }
}
} catch (RemoteException rme) {
// Roll back to previous state
Log.e(TAG, "Unable to list active VPNs", rme);
return;
}
- mCurrentVpnUsers = vpnUsers;
+ mCurrentVpns = vpns;
}
private final NetworkCallback mNetworkCallback = new NetworkCallback() {
@@ -182,5 +232,4 @@ public class SecurityControllerImpl implements SecurityController {
fireCallbacks();
};
};
-
}
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java b/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
index 7472af9..2b76c31 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/QsTuner.java
@@ -315,6 +315,16 @@ public class QsTuner extends Fragment implements Callback {
}
@Override
+ public String getPrimaryVpnName() {
+ return null;
+ }
+
+ @Override
+ public String getProfileVpnName() {
+ return null;
+ }
+
+ @Override
public void onUserSwitched(int newUserId) {
}