diff options
Diffstat (limited to 'packages/SystemUI')
9 files changed, 233 insertions, 6 deletions
diff --git a/packages/SystemUI/res/drawable/ic_delete.xml b/packages/SystemUI/res/drawable/ic_delete.xml new file mode 100644 index 0000000..4e80ddf --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_delete.xml @@ -0,0 +1,24 @@ +<!-- +Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24.0dp" + android:height="24.0dp" + android:viewportWidth="48.0" + android:viewportHeight="48.0"> + <path + android:fillColor="#ffffffff" + android:pathData="M12 38c0 2.21 1.79 4 4 4h16c2.21 0 4,-1.79 4,-4V14H12v24zM38 8h-7l-2,-2H19l-2 2h-7v4h28V8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/ic_person.xml b/packages/SystemUI/res/drawable/ic_person.xml new file mode 100644 index 0000000..101911f --- /dev/null +++ b/packages/SystemUI/res/drawable/ic_person.xml @@ -0,0 +1,24 @@ +<!-- +Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24.0dp" + android:height="24.0dp" + android:viewportWidth="48.0" + android:viewportHeight="48.0"> + <path + android:fillColor="#ffffffff" + android:pathData="M24 24c4.42 0 8,-3.59 8,-8 0,-4.42,-3.58,-8,-8,-8s-8 3.58,-8 8c0 4.41 3.58 8 8 8zm0 4c-5.33 0,-16 2.67,-16 8v4h32v-4c0,-5.33,-10.67,-8,-16,-8z"/> +</vector> diff --git a/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml b/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml new file mode 100644 index 0000000..3c4c646 --- /dev/null +++ b/packages/SystemUI/res/drawable/stat_sys_managed_profile_status.xml @@ -0,0 +1,29 @@ +<!-- +Copyright (C) 2015 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="23.0dp" + android:height="18.0dp" + android:viewportWidth="21.0" + android:viewportHeight="17.0"> + <group android:translateX="2.0"> + <path + android:fillColor="#FF000000" + android:pathData="M9.9,11.6H7v-1.1H2.1v2.8c0,0.8,0.6,1.4,1.4,1.4h9.9c0.8,0,1.4,-0.6,1.4,-1.4v-2.8H9.9V11.6z"/> + <path + android:fillColor="#FF000000" + android:pathData="M14.1,4.2h-2.5V3.2l-1.1,-1.1H6.3L5.3,3.2v1H2.8C2,4.2,1.4,4.9,1.4,5.6v2.8c0,0.8,0.6,1.4,1.4,1.4H7V8.8h2.8v1.1h4.2 c0.8,0,1.4,-0.6,1.4,-1.4V5.6C15.5,4.9,14.8,4.2,14.1,4.2z M10.6,4.2H6.3V3.2h4.2V4.2z"/> + </group> +</vector> diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 807bb19..ae134c6 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -838,6 +838,15 @@ <!-- Notification when resuming an existing guest session: Action that continues with the current session [CHAR LIMIT=35] --> <string name="guest_wipe_session_dontwipe">Yes, continue</string> + <!-- Title of the notification shown to a new guest user [CHAR LIMIT=60] --> + <string name="guest_notification_title">Guest user</string> + + <!-- Text of the notification shown to a new guest user [CHAR LIMIT=60] --> + <string name="guest_notification_text">Remove guest to delete apps and data</string> + + <!-- Remove action in the notification shown to a new guest user [CHAR LIMIT=30] --> + <string name="guest_notification_remove_action">REMOVE GUEST</string> + <!-- Title for add user confirmation dialog [CHAR LIMIT=30] --> <string name="user_add_user_title" msgid="2108112641783146007">Add new user?</string> @@ -990,4 +999,7 @@ <!-- Volume dialog zen toggle switch title --> <string name="volume_zen_switch_text">@*android:string/zen_mode_feature_name</string> + + <!-- Toast shown when user unlocks screen and managed profile activity is in the foreground --> + <string name="managed_profile_foreground_toast">You are in the Work profile</string> </resources> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index d2837b7..ee607a7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -80,6 +80,7 @@ import android.widget.DateTimeView; import android.widget.ImageView; import android.widget.RemoteViews; import android.widget.TextView; +import android.widget.Toast; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.statusbar.StatusBarIcon; @@ -378,6 +379,23 @@ public abstract class BaseStatusBar extends SystemUI implements userSwitched(mCurrentUserId); } else if (Intent.ACTION_USER_ADDED.equals(action)) { updateCurrentProfilesCache(); + } else if (Intent.ACTION_USER_PRESENT.equals(action)) { + List<ActivityManager.RecentTaskInfo> recentTask = null; + try { + recentTask = ActivityManagerNative.getDefault().getRecentTasks(1, + ActivityManager.RECENT_WITH_EXCLUDED + | ActivityManager.RECENT_INCLUDE_PROFILES, + mCurrentUserId); + } catch (RemoteException e) { + // Abandon hope activity manager not running. + } + if (recentTask != null && recentTask.size() > 0) { + UserInfo user = mUserManager.getUserInfo(recentTask.get(0).userId); + if (user != null && user.isManagedProfile()) { + Toast.makeText(mContext, R.string.managed_profile_foreground_toast, + Toast.LENGTH_SHORT).show(); + } + } } else if (DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED.equals( action)) { mUsersAllowingPrivateNotifications.clear(); @@ -612,6 +630,7 @@ public abstract class BaseStatusBar extends SystemUI implements IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_ADDED); + filter.addAction(Intent.ACTION_USER_PRESENT); filter.addAction(BANNER_ACTION_CANCEL); filter.addAction(BANNER_ACTION_SETUP); filter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED); 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 7c199cd..b0d6178 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -3288,8 +3288,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, } if (mState == StatusBarState.KEYGUARD || mState == StatusBarState.SHADE_LOCKED) { mScrimController.setKeyguardShowing(true); + mIconPolicy.setKeyguardShowing(true); } else { mScrimController.setKeyguardShowing(false); + mIconPolicy.setKeyguardShowing(false); } mNotificationPanel.setBarState(mState, mKeyguardFadingAway, goingToFullShade); updateDozingState(); @@ -3724,6 +3726,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, if (!mKeyguardFadingAway) { mIconController.appTransitionStarting(startTime, duration); } + if (mIconPolicy != null) { + mIconPolicy.appTransitionStarting(startTime, duration); + } } private final class ShadeUpdates { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java index ac93ced..fb42ba1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarPolicy.java @@ -16,16 +16,22 @@ package com.android.systemui.statusbar.phone; +import android.app.ActivityManagerNative; import android.app.AlarmManager; +import android.app.IUserSwitchObserver; import android.app.StatusBarManager; import android.bluetooth.BluetoothAdapter; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.pm.UserInfo; import android.media.AudioManager; import android.os.Handler; +import android.os.IRemoteCallback; +import android.os.RemoteException; import android.os.UserHandle; +import android.os.UserManager; import android.provider.Settings.Global; import android.telecom.TelecomManager; import android.util.Log; @@ -54,6 +60,7 @@ public class PhoneStatusBarPolicy { private static final String SLOT_ZEN = "zen"; private static final String SLOT_VOLUME = "volume"; private static final String SLOT_ALARM_CLOCK = "alarm_clock"; + private static final String SLOT_MANAGED_PROFILE = "managed_profile"; private final Context mContext; private final StatusBarManager mService; @@ -72,6 +79,10 @@ public class PhoneStatusBarPolicy { private boolean mBluetoothEnabled = false; + private boolean mManagedProfileFocused = false; + private boolean mManagedProfileIconVisible = true; + + private boolean mKeyguardVisible = true; private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { @Override @@ -94,9 +105,6 @@ public class PhoneStatusBarPolicy { else if (action.equals(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED)) { updateTTY(intent); } - else if (action.equals(Intent.ACTION_USER_SWITCHED)) { - updateAlarm(); - } } }; @@ -115,9 +123,15 @@ public class PhoneStatusBarPolicy { filter.addAction(BluetoothAdapter.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED); filter.addAction(TelecomManager.ACTION_CURRENT_TTY_MODE_CHANGED); - filter.addAction(Intent.ACTION_USER_SWITCHED); mContext.registerReceiver(mIntentReceiver, filter, null, mHandler); + // listen for user / profile change. + try { + ActivityManagerNative.getDefault().registerUserSwitchObserver(mUserSwitchListener); + } catch (RemoteException e) { + // Ignore + } + // TTY status mService.setIcon(SLOT_TTY, R.drawable.stat_sys_tty_mode, 0, null); mService.setIconVisibility(SLOT_TTY, false); @@ -147,6 +161,10 @@ public class PhoneStatusBarPolicy { mService.setIcon(SLOT_HOTSPOT, R.drawable.stat_sys_hotspot, 0, null); mService.setIconVisibility(SLOT_HOTSPOT, mHotspot.isHotspotEnabled()); mHotspot.addCallback(mHotspotCallback); + + // managed profile + mService.setIcon(SLOT_MANAGED_PROFILE, R.drawable.stat_sys_managed_profile_status, 0, null); + mService.setIconVisibility(SLOT_MANAGED_PROFILE, false); } public void setZenMode(int zen) { @@ -298,6 +316,53 @@ public class PhoneStatusBarPolicy { mService.setIconVisibility(SLOT_CAST, isCasting); } + private void profileChanged(int userId) { + UserManager userManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE); + UserInfo user = null; + if (userId == UserHandle.USER_CURRENT) { + try { + user = ActivityManagerNative.getDefault().getCurrentUser(); + } catch (RemoteException e) { + // Ignore + } + } else { + user = userManager.getUserInfo(userId); + } + + mManagedProfileFocused = user != null && user.isManagedProfile(); + if (DEBUG) Log.v(TAG, "profileChanged: mManagedProfileFocused: " + mManagedProfileFocused); + // Actually update the icon later when transition starts. + } + + private void updateManagedProfile() { + if (DEBUG) Log.v(TAG, "updateManagedProfile: mManagedProfileFocused: " + + mManagedProfileFocused + + " mKeyguardVisible: " + mKeyguardVisible); + boolean showIcon = mManagedProfileFocused && !mKeyguardVisible; + if (mManagedProfileIconVisible != showIcon) { + mService.setIconVisibility(SLOT_MANAGED_PROFILE, showIcon); + mManagedProfileIconVisible = showIcon; + } + } + + private final IUserSwitchObserver.Stub mUserSwitchListener = + new IUserSwitchObserver.Stub() { + @Override + public void onUserSwitching(int newUserId, IRemoteCallback reply) { + } + + @Override + public void onUserSwitchComplete(int newUserId) throws RemoteException { + updateAlarm(); + profileChanged(newUserId); + } + + @Override + public void onForegroundProfileSwitch(int newProfileId) { + profileChanged(newProfileId); + } + }; + private final HotspotController.Callback mHotspotCallback = new HotspotController.Callback() { @Override public void onHotspotChanged(boolean enabled) { @@ -311,4 +376,13 @@ public class PhoneStatusBarPolicy { updateCast(); } }; + + public void appTransitionStarting(long startTime, long duration) { + updateManagedProfile(); + } + + public void setKeyguardShowing(boolean visible) { + mKeyguardVisible = visible; + updateManagedProfile(); + } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index 4ac41a1..194bcfa 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -19,6 +19,9 @@ package com.android.systemui.statusbar.policy; import android.app.ActivityManager; import android.app.ActivityManagerNative; import android.app.Dialog; +import android.app.Notification; +import android.app.NotificationManager; +import android.app.PendingIntent; import android.content.BroadcastReceiver; import android.content.Context; import android.content.DialogInterface; @@ -63,6 +66,7 @@ public class UserSwitcherController { private static final boolean DEBUG = false; private static final String SIMPLE_USER_SWITCHER_GLOBAL_SETTING = "lockscreenSimpleUserSwitcher"; + private static final String ACTION_REMOVE_GUEST = "com.android.systemui.REMOVE_GUEST"; private final Context mContext; private final UserManager mUserManager; @@ -89,6 +93,7 @@ public class UserSwitcherController { filter.addAction(Intent.ACTION_USER_INFO_CHANGED); filter.addAction(Intent.ACTION_USER_SWITCHED); filter.addAction(Intent.ACTION_USER_STOPPING); + filter.addAction(ACTION_REMOVE_GUEST); mContext.registerReceiverAsUser(mReceiver, UserHandle.OWNER, filter, null /* permission */, null /* scheduler */); @@ -296,6 +301,22 @@ public class UserSwitcherController { Log.v(TAG, "Broadcast: a=" + intent.getAction() + " user=" + intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1)); } + if (ACTION_REMOVE_GUEST.equals(intent.getAction())) { + int currentUser = ActivityManager.getCurrentUser(); + UserInfo userInfo = mUserManager.getUserInfo(currentUser); + if (userInfo != null && userInfo.isGuest()) { + showExitGuestDialog(currentUser); + } + return; + } + if (Intent.ACTION_USER_ADDED.equals(intent.getAction())) { + final int currentId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1); + UserInfo userInfo = mUserManager.getUserInfo(currentId); + if (userInfo != null && userInfo.isGuest()) { + showGuestNotification(currentId); + } + } + if (Intent.ACTION_USER_SWITCHED.equals(intent.getAction())) { if (mExitGuestDialog != null && mExitGuestDialog.isShowing()) { mExitGuestDialog.cancel(); @@ -329,6 +350,24 @@ public class UserSwitcherController { } refreshUsers(forcePictureLoadForId); } + + private void showGuestNotification(int guestUserId) { + PendingIntent removeGuestPI = PendingIntent.getBroadcastAsUser(mContext, + 0, new Intent(ACTION_REMOVE_GUEST), 0, UserHandle.OWNER); + Notification notification = new Notification.Builder(mContext) + .setVisibility(Notification.VISIBILITY_SECRET) + .setPriority(Notification.PRIORITY_MIN) + .setSmallIcon(R.drawable.ic_person) + .setContentTitle(mContext.getString(R.string.guest_notification_title)) + .setContentText(mContext.getString(R.string.guest_notification_text)) + .setShowWhen(false) + .addAction(R.drawable.ic_delete, + mContext.getString(R.string.guest_notification_remove_action), + removeGuestPI) + .build(); + NotificationManager.from(mContext).notifyAsUser(null, 0, notification, + new UserHandle(guestUserId)); + } }; private final ContentObserver mSettingsObserver = new ContentObserver(new Handler()) { diff --git a/packages/SystemUI/src/com/android/systemui/usb/UsbResolverActivity.java b/packages/SystemUI/src/com/android/systemui/usb/UsbResolverActivity.java index 9928f7f..23a65e8 100644 --- a/packages/SystemUI/src/com/android/systemui/usb/UsbResolverActivity.java +++ b/packages/SystemUI/src/com/android/systemui/usb/UsbResolverActivity.java @@ -93,7 +93,8 @@ public class UsbResolverActivity extends ResolverActivity { } @Override - protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) { + protected void onTargetSelected(TargetInfo target, boolean alwaysCheck) { + final ResolveInfo ri = target.getResolveInfo(); try { IBinder b = ServiceManager.getService(USB_SERVICE); IUsbManager service = IUsbManager.Stub.asInterface(b); @@ -121,7 +122,7 @@ public class UsbResolverActivity extends ResolverActivity { } try { - startActivityAsUser(intent, new UserHandle(userId)); + target.startAsUser(this, null, new UserHandle(userId)); } catch (ActivityNotFoundException e) { Log.e(TAG, "startActivity failed", e); } |