Merge "Don't show suggestion slice if 'Screen attention' is already on" into qt-qpr1-dev
This commit is contained in:
@@ -26,6 +26,7 @@ import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
@@ -72,11 +73,12 @@ public class ContextualAdaptiveSleepSlice implements CustomSliceable {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Display the contextual card only if all the following 3 conditions hold:
|
||||
// 1. The Screen Attention is enabled in Settings.
|
||||
// Display the contextual card only if all the following 4 conditions hold:
|
||||
// 1. The Screen Attention is available in Settings.
|
||||
// 2. The device is not recently set up.
|
||||
// 3. Current user hasn't opened Screen Attention's settings page before.
|
||||
if (isSettingsAvailable() && !isUserInteracted() && !isRecentlySetup()) {
|
||||
// 4. Screen Attention is off.
|
||||
if (isSettingsAvailable() && !isUserInteracted() && !isRecentlySetup() && !isTurnedOn()) {
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_settings_adaptive_sleep);
|
||||
final CharSequence title = mContext.getText(R.string.adaptive_sleep_title);
|
||||
@@ -122,6 +124,14 @@ public class ContextualAdaptiveSleepSlice implements CustomSliceable {
|
||||
return PendingIntent.getActivity(mContext, 0 /* requestCode */, intent, 0 /* flags */);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the feature is turned on for the device, otherwise {@code false}
|
||||
*/
|
||||
private boolean isTurnedOn() {
|
||||
return Settings.System.getInt(
|
||||
mContext.getContentResolver(), Settings.System.ADAPTIVE_SLEEP, 0) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the current user has opened the Screen Attention settings page
|
||||
* before, otherwise {@code false}.
|
||||
|
@@ -32,6 +32,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceProvider;
|
||||
@@ -65,6 +66,7 @@ public class ContextualAdaptiveSleepSliceTest {
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mContextualAdaptiveSleepSlice = spy(new ContextualAdaptiveSleepSlice(mContext));
|
||||
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.ADAPTIVE_SLEEP, 0);
|
||||
doReturn(mPackageManager).when(mContext).getPackageManager();
|
||||
doReturn(mSharedPreferences).when(mContext).getSharedPreferences(eq(PREF), anyInt());
|
||||
doReturn(true).when(mContextualAdaptiveSleepSlice).isSettingsAvailable();
|
||||
@@ -112,4 +114,20 @@ public class ContextualAdaptiveSleepSliceTest {
|
||||
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_ShowIfNotTurnedOn() {
|
||||
final Slice slice = mContextualAdaptiveSleepSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_DoNotShowIfTurnedOn() {
|
||||
Settings.System.putInt(mContext.getContentResolver(), Settings.System.ADAPTIVE_SLEEP, 1);
|
||||
|
||||
final Slice slice = mContextualAdaptiveSleepSlice.getSlice();
|
||||
|
||||
assertThat(slice).isNull();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user