Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7605494c authored by Yi Jiang's avatar Yi Jiang
Browse files

Adds contextual cards for screen attention in Settings Homepage

Bug: 128527964
Test: atest ContextualAdaptiveSleepSliceTest, maually verified.
Change-Id: Ifaea7d8d4391e91cf6cbde38a2506728f55913d8
parent 0fbbad92
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
<!--
  Copyright (C) 2019 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.0"
        android:viewportHeight="24.0">
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M10.67,21H7v-1h3.13c-0.27-0.63-0.46-1.3-0.56-2H7V6h10v3.5c0.69,0,1.36,0.1,2,0.28V3 c0-1.1-0.9-1.99-2-1.99L7,1C5.9,1,5,1.9,5,3v18c0,1.1,0.9,2,2,2h5.52C11.79,22.45,11.16,21.77,10.67,21z M7,3h10v1H7V3z" />
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M17,12.5c2.48,0,4.5,2.02,4.5,4.5s-2.02,4.5-4.5,4.5s-4.5-2.02-4.5-4.5S14.52,12.5,17,12.5 M17,11 c-3.31,0-6,2.69-6,6s2.69,6,6,6c3.31,0,6-2.69,6-6S20.31,11,17,11L17,11z" />
    <path
        android:fillColor="#FFFFFFFF"
        android:pathData="M17,14v3l-2.12,2.12C15.42,19.66,16.17,20,17,20c1.66,0,3-1.34,3-3S18.66,14,17,14z" />
</vector>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -2833,7 +2833,7 @@
    <!-- Setting option summary when adaptive sleep is off [CHAR LIMIT=NONE] -->
    <string name="adaptive_sleep_summary_off">Off</string>
    <!-- Description about the feature adaptive sleep [CHAR LIMIT=NONE]-->
    <string name="adaptive_sleep_description">Prevents your screen from turning off if you’re looking at it.</string>
    <string name="adaptive_sleep_description">Keep screen on when viewing it</string>
    <!-- Description feature's privacy sensitive details to make sure users understand what feature users, what it saves/sends etc [CHAR LIMIT=NONE]-->
    <string name="adaptive_sleep_privacy">Screen attention uses the front camera to see if someone is looking at the screen. It works on device, and images are never stored or sent to Google.</string>
+18 −11
Original line number Diff line number Diff line
@@ -25,9 +25,9 @@ import com.android.settings.core.TogglePreferenceController;


public class AdaptiveSleepPreferenceController extends TogglePreferenceController {

    private final String SYSTEM_KEY = ADAPTIVE_SLEEP;
    private final int DEFAULT_VALUE = 0;
    public static final String PREF_NAME = "adaptive_sleep";
    private static final String SYSTEM_KEY = ADAPTIVE_SLEEP;
    private static final int DEFAULT_VALUE = 0;

    final boolean hasSufficientPermissions;

@@ -35,9 +35,7 @@ public class AdaptiveSleepPreferenceController extends TogglePreferenceControlle
        super(context, key);

        final PackageManager packageManager = mContext.getPackageManager();
        final String attentionPackage = packageManager.getAttentionServicePackageName();
        hasSufficientPermissions = attentionPackage != null && packageManager.checkPermission(
                Manifest.permission.CAMERA, attentionPackage) == PackageManager.PERMISSION_GRANTED;
        hasSufficientPermissions = hasSufficientPermission(packageManager);
    }

    @Override
@@ -46,7 +44,6 @@ public class AdaptiveSleepPreferenceController extends TogglePreferenceControlle
                SYSTEM_KEY, DEFAULT_VALUE) != DEFAULT_VALUE;
    }


    @Override
    public boolean setChecked(boolean isChecked) {
        Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
@@ -57,10 +54,7 @@ public class AdaptiveSleepPreferenceController extends TogglePreferenceControlle
    @Override
    @AvailabilityStatus
    public int getAvailabilityStatus() {
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_adaptive_sleep_available)
                ? AVAILABLE_UNSEARCHABLE
                : UNSUPPORTED_ON_DEVICE;
        return isControllerAvailable(mContext);
    }

    @Override
@@ -69,4 +63,17 @@ public class AdaptiveSleepPreferenceController extends TogglePreferenceControlle
                ? R.string.adaptive_sleep_summary_on
                : R.string.adaptive_sleep_summary_off);
    }

    public static int isControllerAvailable(Context context) {
        return context.getResources().getBoolean(
                com.android.internal.R.bool.config_adaptive_sleep_available)
                ? AVAILABLE_UNSEARCHABLE
                : UNSUPPORTED_ON_DEVICE;
    }

    private static boolean hasSufficientPermission(PackageManager packageManager) {
        final String attentionPackage = packageManager.getAttentionServicePackageName();
        return attentionPackage != null && packageManager.checkPermission(
                Manifest.permission.CAMERA, attentionPackage) == PackageManager.PERMISSION_GRANTED;
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -16,10 +16,15 @@

package com.android.settings.display;

import static com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice.PREF;
import static com.android.settings.homepage.contextualcards.slices.ContextualAdaptiveSleepSlice.PREF_KEY_INTERACTED;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.util.Log;

import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -40,8 +45,15 @@ public class AdaptiveSleepSettings extends DashboardFragment {
        super.onCreate(icicle);
        final FooterPreference footerPreference =
                mFooterPreferenceMixin.createFooterPreference();
        final Context context = getContext();

        footerPreference.setIcon(R.drawable.ic_privacy_shield_24dp);
        footerPreference.setTitle(R.string.adaptive_sleep_privacy);

        context.getSharedPreferences(PREF, Context.MODE_PRIVATE)
                .edit()
                .putBoolean(PREF_KEY_INTERACTED, true)
                .apply();
    }

    @Override
+9 −0
Original line number Diff line number Diff line
@@ -64,12 +64,21 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
                        .setCardName(contextualNotificationChannelSliceUri)
                        .setCardCategory(ContextualCard.Category.POSSIBLE)
                        .build();
        final String contextualAdaptiveSleepSliceUri =
                CustomSliceRegistry.CONTEXTUAL_ADAPTIVE_SLEEP_URI.toString();
        final ContextualCard contextualAdaptiveSleepCard =
                ContextualCard.newBuilder()
                        .setSliceUri(contextualAdaptiveSleepSliceUri)
                        .setCardName(contextualAdaptiveSleepSliceUri)
                        .setCardCategory(ContextualCard.Category.DEFAULT)
                        .build();
        final ContextualCardList cards = ContextualCardList.newBuilder()
                .addCard(wifiCard)
                .addCard(connectedDeviceCard)
                .addCard(lowStorageCard)
                .addCard(batteryFixCard)
                .addCard(notificationChannelCard)
                .addCard(contextualAdaptiveSleepCard)
                .build();

        return cards;
Loading