Merge "DarkMode Tile affects all users + security bug" into rvc-qpr-dev
This commit is contained in:
@@ -510,6 +510,9 @@ public class UiModeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Activating night mode for the current user
|
||||||
|
*
|
||||||
|
* @return {@code true} if the change is successful
|
||||||
* @hide
|
* @hide
|
||||||
*/
|
*/
|
||||||
public boolean setNightModeActivated(boolean active) {
|
public boolean setNightModeActivated(boolean active) {
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public class NightDisplayTile extends QSTileImpl<BooleanState> implements
|
|||||||
private static final String PATTERN_HOUR_MINUTE = "h:mm a";
|
private static final String PATTERN_HOUR_MINUTE = "h:mm a";
|
||||||
private static final String PATTERN_HOUR_NINUTE_24 = "HH:mm";
|
private static final String PATTERN_HOUR_NINUTE_24 = "HH:mm";
|
||||||
|
|
||||||
private final ColorDisplayManager mManager;
|
private ColorDisplayManager mManager;
|
||||||
private final LocationController mLocationController;
|
private final LocationController mLocationController;
|
||||||
private NightDisplayListener mListener;
|
private NightDisplayListener mListener;
|
||||||
private boolean mIsListening;
|
private boolean mIsListening;
|
||||||
@@ -105,6 +105,8 @@ public class NightDisplayTile extends QSTileImpl<BooleanState> implements
|
|||||||
mListener.setCallback(null);
|
mListener.setCallback(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mManager = getHost().getUserContext().getSystemService(ColorDisplayManager.class);
|
||||||
|
|
||||||
// Make a new controller for the new user.
|
// Make a new controller for the new user.
|
||||||
mListener = new NightDisplayListener(mContext, newUserId, new Handler(Looper.myLooper()));
|
mListener = new NightDisplayListener(mContext, newUserId, new Handler(Looper.myLooper()));
|
||||||
if (mIsListening) {
|
if (mIsListening) {
|
||||||
|
|||||||
@@ -50,16 +50,15 @@ public class UiModeNightTile extends QSTileImpl<QSTile.BooleanState> implements
|
|||||||
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
|
public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("hh:mm a");
|
||||||
private final Icon mIcon = ResourceIcon.get(
|
private final Icon mIcon = ResourceIcon.get(
|
||||||
com.android.internal.R.drawable.ic_qs_ui_mode_night);
|
com.android.internal.R.drawable.ic_qs_ui_mode_night);
|
||||||
private final UiModeManager mUiModeManager;
|
private UiModeManager mUiModeManager;
|
||||||
private final BatteryController mBatteryController;
|
private final BatteryController mBatteryController;
|
||||||
private final LocationController mLocationController;
|
private final LocationController mLocationController;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public UiModeNightTile(QSHost host, ConfigurationController configurationController,
|
public UiModeNightTile(QSHost host, ConfigurationController configurationController,
|
||||||
BatteryController batteryController, LocationController locationController) {
|
BatteryController batteryController, LocationController locationController) {
|
||||||
super(host);
|
super(host);
|
||||||
mBatteryController = batteryController;
|
mBatteryController = batteryController;
|
||||||
mUiModeManager = mContext.getSystemService(UiModeManager.class);
|
mUiModeManager = host.getUserContext().getSystemService(UiModeManager.class);
|
||||||
mLocationController = locationController;
|
mLocationController = locationController;
|
||||||
configurationController.observe(getLifecycle(), this);
|
configurationController.observe(getLifecycle(), this);
|
||||||
batteryController.observe(getLifecycle(), this);
|
batteryController.observe(getLifecycle(), this);
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
int mCurUiMode = 0;
|
int mCurUiMode = 0;
|
||||||
private int mSetUiMode = 0;
|
private int mSetUiMode = 0;
|
||||||
private boolean mHoldingConfiguration = false;
|
private boolean mHoldingConfiguration = false;
|
||||||
|
private int mCurrentUser;
|
||||||
|
|
||||||
private Configuration mConfiguration = new Configuration();
|
private Configuration mConfiguration = new Configuration();
|
||||||
boolean mSystemReady;
|
boolean mSystemReady;
|
||||||
@@ -323,6 +324,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
@Override
|
@Override
|
||||||
public void onSwitchUser(int userHandle) {
|
public void onSwitchUser(int userHandle) {
|
||||||
super.onSwitchUser(userHandle);
|
super.onSwitchUser(userHandle);
|
||||||
|
mCurrentUser = userHandle;
|
||||||
getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
|
getContext().getContentResolver().unregisterContentObserver(mSetupWizardObserver);
|
||||||
verifySetupWizardCompleted();
|
verifySetupWizardCompleted();
|
||||||
}
|
}
|
||||||
@@ -728,16 +730,30 @@ final class UiModeManagerService extends SystemService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean setNightModeActivated(boolean active) {
|
public boolean setNightModeActivated(boolean active) {
|
||||||
|
if (isNightModeLocked() && (getContext().checkCallingOrSelfPermission(
|
||||||
|
android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED)) {
|
||||||
|
Slog.e(TAG, "Night mode locked, requires MODIFY_DAY_NIGHT_MODE permission");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final int user = Binder.getCallingUserHandle().getIdentifier();
|
||||||
|
if (user != mCurrentUser && getContext().checkCallingOrSelfPermission(
|
||||||
|
android.Manifest.permission.INTERACT_ACROSS_USERS)
|
||||||
|
!= PackageManager.PERMISSION_GRANTED) {
|
||||||
|
Slog.e(TAG, "Target user is not current user,"
|
||||||
|
+ " INTERACT_ACROSS_USERS permission is required");
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
synchronized (mLock) {
|
synchronized (mLock) {
|
||||||
final int user = UserHandle.getCallingUserId();
|
|
||||||
final long ident = Binder.clearCallingIdentity();
|
final long ident = Binder.clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
if (mNightMode == MODE_NIGHT_AUTO || mNightMode == MODE_NIGHT_CUSTOM) {
|
if (mNightMode == MODE_NIGHT_AUTO || mNightMode == MODE_NIGHT_CUSTOM) {
|
||||||
unregisterScreenOffEventLocked();
|
unregisterScreenOffEventLocked();
|
||||||
mOverrideNightModeOff = !active;
|
mOverrideNightModeOff = !active;
|
||||||
mOverrideNightModeOn = active;
|
mOverrideNightModeOn = active;
|
||||||
mOverrideNightModeUser = user;
|
mOverrideNightModeUser = mCurrentUser;
|
||||||
persistNightModeOverrides(user);
|
persistNightModeOverrides(mCurrentUser);
|
||||||
} else if (mNightMode == UiModeManager.MODE_NIGHT_NO
|
} else if (mNightMode == UiModeManager.MODE_NIGHT_NO
|
||||||
&& active) {
|
&& active) {
|
||||||
mNightMode = UiModeManager.MODE_NIGHT_YES;
|
mNightMode = UiModeManager.MODE_NIGHT_YES;
|
||||||
@@ -747,7 +763,7 @@ final class UiModeManagerService extends SystemService {
|
|||||||
}
|
}
|
||||||
updateConfigurationLocked();
|
updateConfigurationLocked();
|
||||||
applyConfigurationExternallyLocked();
|
applyConfigurationExternallyLocked();
|
||||||
persistNightMode(user);
|
persistNightMode(mCurrentUser);
|
||||||
return true;
|
return true;
|
||||||
} finally {
|
} finally {
|
||||||
Binder.restoreCallingIdentity(ident);
|
Binder.restoreCallingIdentity(ident);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.android.server;
|
package com.android.server;
|
||||||
|
|
||||||
|
import android.Manifest;
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.IUiModeManager;
|
import android.app.IUiModeManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
@@ -24,6 +25,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -66,6 +68,7 @@ import static org.mockito.Mockito.atLeast;
|
|||||||
import static org.mockito.Mockito.atLeastOnce;
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.doAnswer;
|
import static org.mockito.Mockito.doAnswer;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -226,6 +229,15 @@ public class UiModeManagerServiceTest extends UiServiceTestCase {
|
|||||||
assertFalse(isNightModeActivated());
|
assertFalse(isNightModeActivated());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setNightModeActivated_permissiontoChangeOtherUsers() throws RemoteException {
|
||||||
|
mUiManagerService.onSwitchUser(9);
|
||||||
|
when(mContext.checkCallingOrSelfPermission(
|
||||||
|
eq(Manifest.permission.INTERACT_ACROSS_USERS)))
|
||||||
|
.thenReturn(PackageManager.PERMISSION_DENIED);
|
||||||
|
assertFalse(mService.setNightModeActivated(true));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void autoNightModeSwitch_batterySaverOn() throws RemoteException {
|
public void autoNightModeSwitch_batterySaverOn() throws RemoteException {
|
||||||
mService.setNightMode(MODE_NIGHT_NO);
|
mService.setNightMode(MODE_NIGHT_NO);
|
||||||
|
|||||||
Reference in New Issue
Block a user