Merge "Show disclosure for work profile on org owned device in keyguard" into rvc-dev am: 59804dccba
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11931086 Change-Id: I9a29b2c89f51573df0fdb930f70f0d98b2becdd4
This commit is contained in:
@@ -25,6 +25,7 @@ import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.hardware.biometrics.BiometricSourceType;
|
||||
@@ -34,12 +35,16 @@ import android.os.BatteryManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.app.IBatteryStats;
|
||||
import com.android.internal.widget.ViewClippingUtil;
|
||||
@@ -96,6 +101,7 @@ public class KeyguardIndicationController implements StateListener,
|
||||
private final SettableWakeLock mWakeLock;
|
||||
private final DockManager mDockManager;
|
||||
private final DevicePolicyManager mDevicePolicyManager;
|
||||
private final UserManager mUserManager;
|
||||
|
||||
private BroadcastReceiver mBroadcastReceiver;
|
||||
private LockscreenLockIconController mLockIconController;
|
||||
@@ -142,7 +148,8 @@ public class KeyguardIndicationController implements StateListener,
|
||||
DockManager dockManager,
|
||||
BroadcastDispatcher broadcastDispatcher,
|
||||
DevicePolicyManager devicePolicyManager,
|
||||
IBatteryStats iBatteryStats) {
|
||||
IBatteryStats iBatteryStats,
|
||||
UserManager userManager) {
|
||||
mContext = context;
|
||||
mBroadcastDispatcher = broadcastDispatcher;
|
||||
mDevicePolicyManager = devicePolicyManager;
|
||||
@@ -155,6 +162,7 @@ public class KeyguardIndicationController implements StateListener,
|
||||
mWakeLock = new SettableWakeLock(
|
||||
wakeLockBuilder.setTag("Doze:KeyguardIndication").build(), TAG);
|
||||
mBatteryInfo = iBatteryStats;
|
||||
mUserManager = userManager;
|
||||
|
||||
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
|
||||
mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
|
||||
@@ -180,8 +188,10 @@ public class KeyguardIndicationController implements StateListener,
|
||||
updateDisclosure();
|
||||
}
|
||||
};
|
||||
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, new IntentFilter(
|
||||
DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED));
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED);
|
||||
intentFilter.addAction(Intent.ACTION_USER_REMOVED);
|
||||
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, intentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,9 +233,8 @@ public class KeyguardIndicationController implements StateListener,
|
||||
|
||||
private void updateDisclosure() {
|
||||
// NOTE: Because this uses IPC, avoid calling updateDisclosure() on a critical path.
|
||||
if (whitelistIpcs(mDevicePolicyManager::isDeviceManaged)) {
|
||||
final CharSequence organizationName =
|
||||
mDevicePolicyManager.getDeviceOwnerOrganizationName();
|
||||
if (whitelistIpcs(this::isOrganizationOwnedDevice)) {
|
||||
CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName();
|
||||
if (organizationName != null) {
|
||||
mDisclosure.switchIndication(mContext.getResources().getString(
|
||||
R.string.do_disclosure_with_name, organizationName));
|
||||
@@ -238,6 +247,38 @@ public class KeyguardIndicationController implements StateListener,
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOrganizationOwnedDevice() {
|
||||
return mDevicePolicyManager.isDeviceManaged()
|
||||
|| mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CharSequence getOrganizationOwnedDeviceOrganizationName() {
|
||||
if (mDevicePolicyManager.isDeviceManaged()) {
|
||||
return mDevicePolicyManager.getDeviceOwnerOrganizationName();
|
||||
} else if (mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()) {
|
||||
return getWorkProfileOrganizationName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private CharSequence getWorkProfileOrganizationName() {
|
||||
final int profileId = getWorkProfileUserId(UserHandle.myUserId());
|
||||
if (profileId == UserHandle.USER_NULL) {
|
||||
return null;
|
||||
}
|
||||
return mDevicePolicyManager.getOrganizationNameForUser(profileId);
|
||||
}
|
||||
|
||||
private int getWorkProfileUserId(int userId) {
|
||||
for (final UserInfo userInfo : mUserManager.getProfiles(userId)) {
|
||||
if (userInfo.isManagedProfile()) {
|
||||
return userInfo.id;
|
||||
}
|
||||
}
|
||||
return UserHandle.USER_NULL;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
mVisible = visible;
|
||||
mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.systemui.statusbar;
|
||||
|
||||
import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -40,6 +42,7 @@ import android.app.trust.TrustManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.Color;
|
||||
import android.hardware.biometrics.BiometricSourceType;
|
||||
import android.hardware.face.FaceManager;
|
||||
@@ -79,6 +82,8 @@ import org.mockito.Captor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@@ -154,7 +159,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
|
||||
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
|
||||
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
|
||||
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats);
|
||||
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats,
|
||||
mUserManager);
|
||||
mController.setIndicationArea(mIndicationArea);
|
||||
mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
|
||||
clearInvocations(mIBatteryStats);
|
||||
@@ -242,6 +248,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void disclosure_unmanaged() {
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);
|
||||
createController();
|
||||
|
||||
verify(mDisclosure).setVisibility(View.GONE);
|
||||
@@ -249,7 +256,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_managedNoOwnerName() {
|
||||
public void disclosure_deviceOwner_noOwnerName() {
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
createController();
|
||||
@@ -259,6 +266,19 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
verifyNoMoreInteractions(mDisclosure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_orgOwnedDeviceWithManagedProfile_noOwnerName() {
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
|
||||
new UserInfo(10, /* name */ null, /* flags */ FLAG_MANAGED_PROFILE)));
|
||||
when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(null);
|
||||
createController();
|
||||
|
||||
verify(mDisclosure).setVisibility(View.VISIBLE);
|
||||
verify(mDisclosure).switchIndication(R.string.do_disclosure_generic);
|
||||
verifyNoMoreInteractions(mDisclosure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_hiddenWhenDozing() {
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
@@ -292,7 +312,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_managedOwnerName() {
|
||||
public void disclosure_deviceOwner_withOwnerName() {
|
||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
|
||||
createController();
|
||||
@@ -302,6 +322,19 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||
verifyNoMoreInteractions(mDisclosure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_orgOwnedDeviceWithManagedProfile_withOwnerName() {
|
||||
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(true);
|
||||
when(mUserManager.getProfiles(anyInt())).thenReturn(Collections.singletonList(
|
||||
new UserInfo(10, /* name */ null, FLAG_MANAGED_PROFILE)));
|
||||
when(mDevicePolicyManager.getOrganizationNameForUser(eq(10))).thenReturn(ORGANIZATION_NAME);
|
||||
createController();
|
||||
|
||||
verify(mDisclosure).setVisibility(View.VISIBLE);
|
||||
verify(mDisclosure).switchIndication(mDisclosureWithOrganization);
|
||||
verifyNoMoreInteractions(mDisclosure);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void disclosure_updateOnTheFly() {
|
||||
ArgumentCaptor<BroadcastReceiver> receiver = ArgumentCaptor.forClass(
|
||||
|
||||
Reference in New Issue
Block a user