Update screensaver tile icon based on docking state.
Updates the screensaver tile icon based on the state of the dock. Useful for debugging purposes. Bug: 235536605 Test: Wrote new test, also tested manually on device with hardware dock Change-Id: Ibff675fe915b4e5977cc3f6dfd737f28c4b0d26a
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<!--
|
||||
Copyright (C) 2022 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="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M14.5,9l-3.5,4.51l-2.5,-3.01l-3.5,4.5l14,0z"
|
||||
/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M21,4H3C1.9,4 1,4.9 1,6V17C1,18.1 1.9,19 3,19H5H19H21C22.1,19 23,18.1 23,17V6C23,4.9 22.1,4 21,4ZM21,17H3V6H21V17Z"
|
||||
/>
|
||||
</vector>
|
||||
@@ -61,7 +61,9 @@ import javax.inject.Named;
|
||||
public class DreamTile extends QSTileImpl<QSTile.BooleanState> {
|
||||
|
||||
private static final String LOG_TAG = "QSDream";
|
||||
private final Icon mIcon = ResourceIcon.get(R.drawable.ic_qs_screen_saver);
|
||||
// TODO: consider 1 animated icon instead
|
||||
private final Icon mIconDocked = ResourceIcon.get(R.drawable.ic_qs_screen_saver);
|
||||
private final Icon mIconUndocked = ResourceIcon.get(R.drawable.ic_qs_screen_saver_undocked);
|
||||
private final IDreamManager mDreamManager;
|
||||
private final BroadcastDispatcher mBroadcastDispatcher;
|
||||
private final SettingObserver mEnabledSettingObserver;
|
||||
@@ -70,9 +72,15 @@ public class DreamTile extends QSTileImpl<QSTile.BooleanState> {
|
||||
private final boolean mDreamSupported;
|
||||
private final boolean mDreamOnlyEnabledForSystemUser;
|
||||
|
||||
private boolean mIsDocked = false;
|
||||
|
||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
|
||||
mIsDocked = intent.getIntExtra(Intent.EXTRA_DOCK_STATE, -1)
|
||||
!= Intent.EXTRA_DOCK_STATE_UNDOCKED;
|
||||
}
|
||||
refreshState();
|
||||
}
|
||||
};
|
||||
@@ -126,6 +134,7 @@ public class DreamTile extends QSTileImpl<QSTile.BooleanState> {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(Intent.ACTION_DREAMING_STARTED);
|
||||
filter.addAction(Intent.ACTION_DREAMING_STOPPED);
|
||||
filter.addAction(Intent.ACTION_DOCK_EVENT);
|
||||
mBroadcastDispatcher.registerReceiver(mReceiver, filter);
|
||||
} else {
|
||||
mBroadcastDispatcher.unregisterReceiver(mReceiver);
|
||||
@@ -168,7 +177,7 @@ public class DreamTile extends QSTileImpl<QSTile.BooleanState> {
|
||||
state.label = getTileLabel();
|
||||
state.secondaryLabel = getActiveDreamName();
|
||||
state.contentDescription = getContentDescription(state.secondaryLabel);
|
||||
state.icon = mIcon;
|
||||
state.icon = mIsDocked ? mIconDocked : mIconUndocked;
|
||||
|
||||
if (getActiveDream() == null || !isScreensaverEnabled()) {
|
||||
state.state = Tile.STATE_UNAVAILABLE;
|
||||
|
||||
@@ -20,12 +20,15 @@ import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertFalse;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
@@ -46,6 +49,7 @@ import com.android.systemui.plugins.ActivityStarter;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.qs.QSTileHost;
|
||||
import com.android.systemui.qs.logging.QSLogger;
|
||||
import com.android.systemui.qs.tileimpl.QSTileImpl;
|
||||
import com.android.systemui.settings.UserTracker;
|
||||
import com.android.systemui.util.settings.FakeSettings;
|
||||
import com.android.systemui.util.settings.SecureSettings;
|
||||
@@ -53,6 +57,7 @@ import com.android.systemui.util.settings.SecureSettings;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
@@ -216,6 +221,30 @@ public class DreamTileTest extends SysuiTestCase {
|
||||
assertFalse(supportedTileOnlySystemUser.isAvailable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIconDockState() {
|
||||
final DreamTile dockedTile = constructTileForTest(true, false);
|
||||
|
||||
final ArgumentCaptor<BroadcastReceiver> receiverCaptor = ArgumentCaptor.forClass(
|
||||
BroadcastReceiver.class);
|
||||
dockedTile.handleSetListening(true);
|
||||
verify(mBroadcastDispatcher).registerReceiver(receiverCaptor.capture(), any());
|
||||
final BroadcastReceiver receiver = receiverCaptor.getValue();
|
||||
|
||||
Intent dockIntent = new Intent(Intent.ACTION_DOCK_EVENT);
|
||||
dockIntent.putExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_DESK);
|
||||
receiver.onReceive(mContext, dockIntent);
|
||||
mTestableLooper.processAllMessages();
|
||||
assertEquals(QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_screen_saver),
|
||||
dockedTile.getState().icon);
|
||||
|
||||
dockIntent.putExtra(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
|
||||
receiver.onReceive(mContext, dockIntent);
|
||||
mTestableLooper.processAllMessages();
|
||||
assertEquals(QSTileImpl.ResourceIcon.get(R.drawable.ic_qs_screen_saver_undocked),
|
||||
dockedTile.getState().icon);
|
||||
}
|
||||
|
||||
private void setScreensaverEnabled(boolean enabled) {
|
||||
mSecureSettings.putIntForUser(Settings.Secure.SCREENSAVER_ENABLED, enabled ? 1 : 0,
|
||||
DEFAULT_USER);
|
||||
|
||||
Reference in New Issue
Block a user