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.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.hardware.biometrics.BiometricSourceType;
|
import android.hardware.biometrics.BiometricSourceType;
|
||||||
@@ -34,12 +35,16 @@ import android.os.BatteryManager;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.format.Formatter;
|
import android.text.format.Formatter;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.internal.app.IBatteryStats;
|
import com.android.internal.app.IBatteryStats;
|
||||||
import com.android.internal.widget.ViewClippingUtil;
|
import com.android.internal.widget.ViewClippingUtil;
|
||||||
@@ -96,6 +101,7 @@ public class KeyguardIndicationController implements StateListener,
|
|||||||
private final SettableWakeLock mWakeLock;
|
private final SettableWakeLock mWakeLock;
|
||||||
private final DockManager mDockManager;
|
private final DockManager mDockManager;
|
||||||
private final DevicePolicyManager mDevicePolicyManager;
|
private final DevicePolicyManager mDevicePolicyManager;
|
||||||
|
private final UserManager mUserManager;
|
||||||
|
|
||||||
private BroadcastReceiver mBroadcastReceiver;
|
private BroadcastReceiver mBroadcastReceiver;
|
||||||
private LockscreenLockIconController mLockIconController;
|
private LockscreenLockIconController mLockIconController;
|
||||||
@@ -142,7 +148,8 @@ public class KeyguardIndicationController implements StateListener,
|
|||||||
DockManager dockManager,
|
DockManager dockManager,
|
||||||
BroadcastDispatcher broadcastDispatcher,
|
BroadcastDispatcher broadcastDispatcher,
|
||||||
DevicePolicyManager devicePolicyManager,
|
DevicePolicyManager devicePolicyManager,
|
||||||
IBatteryStats iBatteryStats) {
|
IBatteryStats iBatteryStats,
|
||||||
|
UserManager userManager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
mBroadcastDispatcher = broadcastDispatcher;
|
mBroadcastDispatcher = broadcastDispatcher;
|
||||||
mDevicePolicyManager = devicePolicyManager;
|
mDevicePolicyManager = devicePolicyManager;
|
||||||
@@ -155,6 +162,7 @@ public class KeyguardIndicationController implements StateListener,
|
|||||||
mWakeLock = new SettableWakeLock(
|
mWakeLock = new SettableWakeLock(
|
||||||
wakeLockBuilder.setTag("Doze:KeyguardIndication").build(), TAG);
|
wakeLockBuilder.setTag("Doze:KeyguardIndication").build(), TAG);
|
||||||
mBatteryInfo = iBatteryStats;
|
mBatteryInfo = iBatteryStats;
|
||||||
|
mUserManager = userManager;
|
||||||
|
|
||||||
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
|
mKeyguardUpdateMonitor.registerCallback(getKeyguardCallback());
|
||||||
mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
|
mKeyguardUpdateMonitor.registerCallback(mTickReceiver);
|
||||||
@@ -180,8 +188,10 @@ public class KeyguardIndicationController implements StateListener,
|
|||||||
updateDisclosure();
|
updateDisclosure();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
mBroadcastDispatcher.registerReceiver(mBroadcastReceiver, new IntentFilter(
|
IntentFilter intentFilter = new IntentFilter();
|
||||||
DevicePolicyManager.ACTION_DEVICE_POLICY_MANAGER_STATE_CHANGED));
|
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() {
|
private void updateDisclosure() {
|
||||||
// NOTE: Because this uses IPC, avoid calling updateDisclosure() on a critical path.
|
// NOTE: Because this uses IPC, avoid calling updateDisclosure() on a critical path.
|
||||||
if (whitelistIpcs(mDevicePolicyManager::isDeviceManaged)) {
|
if (whitelistIpcs(this::isOrganizationOwnedDevice)) {
|
||||||
final CharSequence organizationName =
|
CharSequence organizationName = getOrganizationOwnedDeviceOrganizationName();
|
||||||
mDevicePolicyManager.getDeviceOwnerOrganizationName();
|
|
||||||
if (organizationName != null) {
|
if (organizationName != null) {
|
||||||
mDisclosure.switchIndication(mContext.getResources().getString(
|
mDisclosure.switchIndication(mContext.getResources().getString(
|
||||||
R.string.do_disclosure_with_name, organizationName));
|
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) {
|
public void setVisible(boolean visible) {
|
||||||
mVisible = visible;
|
mVisible = visible;
|
||||||
mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE);
|
mIndicationArea.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.systemui.statusbar;
|
package com.android.systemui.statusbar;
|
||||||
|
|
||||||
|
import static android.content.pm.UserInfo.FLAG_MANAGED_PROFILE;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
@@ -40,6 +42,7 @@ import android.app.trust.TrustManager;
|
|||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.hardware.biometrics.BiometricSourceType;
|
import android.hardware.biometrics.BiometricSourceType;
|
||||||
import android.hardware.face.FaceManager;
|
import android.hardware.face.FaceManager;
|
||||||
@@ -79,6 +82,8 @@ import org.mockito.Captor;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
||||||
@@ -154,7 +159,8 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
|
|
||||||
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
|
mController = new KeyguardIndicationController(mContext, mWakeLockBuilder,
|
||||||
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
|
mKeyguardStateController, mStatusBarStateController, mKeyguardUpdateMonitor,
|
||||||
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats);
|
mDockManager, mBroadcastDispatcher, mDevicePolicyManager, mIBatteryStats,
|
||||||
|
mUserManager);
|
||||||
mController.setIndicationArea(mIndicationArea);
|
mController.setIndicationArea(mIndicationArea);
|
||||||
mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
|
mController.setStatusBarKeyguardViewManager(mStatusBarKeyguardViewManager);
|
||||||
clearInvocations(mIBatteryStats);
|
clearInvocations(mIBatteryStats);
|
||||||
@@ -242,6 +248,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
@Test
|
@Test
|
||||||
public void disclosure_unmanaged() {
|
public void disclosure_unmanaged() {
|
||||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
|
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(false);
|
||||||
|
when(mDevicePolicyManager.isOrganizationOwnedDeviceWithManagedProfile()).thenReturn(false);
|
||||||
createController();
|
createController();
|
||||||
|
|
||||||
verify(mDisclosure).setVisibility(View.GONE);
|
verify(mDisclosure).setVisibility(View.GONE);
|
||||||
@@ -249,7 +256,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disclosure_managedNoOwnerName() {
|
public void disclosure_deviceOwner_noOwnerName() {
|
||||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||||
createController();
|
createController();
|
||||||
@@ -259,6 +266,19 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
verifyNoMoreInteractions(mDisclosure);
|
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
|
@Test
|
||||||
public void disclosure_hiddenWhenDozing() {
|
public void disclosure_hiddenWhenDozing() {
|
||||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||||
@@ -292,7 +312,7 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disclosure_managedOwnerName() {
|
public void disclosure_deviceOwner_withOwnerName() {
|
||||||
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
when(mDevicePolicyManager.isDeviceManaged()).thenReturn(true);
|
||||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
|
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(ORGANIZATION_NAME);
|
||||||
createController();
|
createController();
|
||||||
@@ -302,6 +322,19 @@ public class KeyguardIndicationControllerTest extends SysuiTestCase {
|
|||||||
verifyNoMoreInteractions(mDisclosure);
|
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
|
@Test
|
||||||
public void disclosure_updateOnTheFly() {
|
public void disclosure_updateOnTheFly() {
|
||||||
ArgumentCaptor<BroadcastReceiver> receiver = ArgumentCaptor.forClass(
|
ArgumentCaptor<BroadcastReceiver> receiver = ArgumentCaptor.forClass(
|
||||||
|
|||||||
Reference in New Issue
Block a user