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

Commit 2bd74f7e authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add accessibility usage preference to the Privacy screen."

parents 1de961d9 1d3df216
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -10636,6 +10636,15 @@
    <!-- Text for permission bar chart details in Privacy page.  [CHAR LIMIT=NONE] -->
    <!-- Text for permission bar chart details in Privacy page.  [CHAR LIMIT=NONE] -->
    <string name="permission_bar_chart_details">See all usage</string>
    <string name="permission_bar_chart_details">See all usage</string>
    <!-- Title for the accessibility usage preference in the Privacy page.  [CHAR LIMIT=NONE] -->
    <string name="accessibility_usage_title">Accessibility usage</string>
    <!-- Summary for the accessibility usage preference in the Privacy page.  [CHAR LIMIT=NONE] -->
    <plurals name="accessibility_usage_summary">
        <item quantity="one">1 service has full access to your device</item>
        <item quantity="other"><xliff:g id="service_count">%1$d</xliff:g> services have full access to your device</item>
    </plurals>
    <!-- Title for notification channel slice. [CHAR LIMIT=NONE] -->
    <!-- Title for notification channel slice. [CHAR LIMIT=NONE] -->
    <string name="manage_app_notification">Manage <xliff:g id="app_name" example="Settings">%1$s</xliff:g> Notifications</string>
    <string name="manage_app_notification">Manage <xliff:g id="app_name" example="Settings">%1$s</xliff:g> Notifications</string>
    <!-- Title for no suggested app in notification channel slice. [CHAR LIMIT=NONE] -->
    <!-- Title for no suggested app in notification channel slice. [CHAR LIMIT=NONE] -->
+10 −1
Original line number Original line Diff line number Diff line
@@ -20,13 +20,22 @@
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="privacy_dashboard_page"
    android:key="privacy_dashboard_page"
    android:title="@string/privacy_dashboard_title"
    android:title="@string/privacy_dashboard_title"
    settings:initialExpandedChildrenCount="3">
    settings:initialExpandedChildrenCount="4">


    <com.android.settingslib.widget.BarChartPreference
    <com.android.settingslib.widget.BarChartPreference
        android:key="permission_bar_chart"
        android:key="permission_bar_chart"
        android:title="@string/privacy_dashboard_title"
        android:title="@string/privacy_dashboard_title"
        settings:controller="com.android.settings.privacy.PermissionBarChartPreferenceController"/>
        settings:controller="com.android.settings.privacy.PermissionBarChartPreferenceController"/>


    <!-- Accessibility usage -->
    <Preference
        android:key="privacy_accessibility_usage"
        android:title="@string/accessibility_usage_title"
        settings:allowDividerAbove="true"
        settings:controller="com.android.settings.privacy.AccessibilityUsagePreferenceController">
        <intent android:action="android.intent.action.REVIEW_ACCESSIBILITY_SERVICES"/>
    </Preference>

    <!-- App permissions -->
    <!-- App permissions -->
    <Preference
    <Preference
        android:key="privacy_manage_perms"
        android:key="privacy_manage_perms"
+55 −0
Original line number Original line 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.
 */

package com.android.settings.privacy;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.view.accessibility.AccessibilityManager;

import androidx.annotation.NonNull;
import androidx.preference.Preference;

import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;

import java.util.List;


public class AccessibilityUsagePreferenceController extends BasePreferenceController  {

    private final @NonNull List<AccessibilityServiceInfo> mEnabledServiceInfos;

    public AccessibilityUsagePreferenceController(Context context, String preferenceKey) {
        super(context, preferenceKey);

        final AccessibilityManager accessibilityManager = context.getSystemService(
                AccessibilityManager.class);
        mEnabledServiceInfos = accessibilityManager.getEnabledAccessibilityServiceList(
                AccessibilityServiceInfo.FEEDBACK_ALL_MASK);
    }

    @Override
    public int getAvailabilityStatus() {
        return mEnabledServiceInfos.isEmpty() ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
    }

    @Override
    public CharSequence getSummary() {
        return mContext.getResources().getQuantityString(R.plurals.accessibility_usage_summary,
                mEnabledServiceInfos.size(), mEnabledServiceInfos.size());
    }
}
+77 −0
Original line number Original line 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.
 */

package com.android.settings.privacy;

import static com.android.settings.core.BasePreferenceController.AVAILABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;

import static com.google.common.truth.Truth.assertThat;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.view.accessibility.AccessibilityManager;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowAccessibilityManager;

import java.util.ArrayList;
import java.util.Arrays;

@RunWith(RobolectricTestRunner.class)
public class AccessibilityUsagePreferenceControllerTest {

    private Context mContext;
    private ShadowAccessibilityManager mAccessibilityManager;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
        mContext = RuntimeEnvironment.application;
        mAccessibilityManager = Shadow.extract(
                RuntimeEnvironment.application.getSystemService(AccessibilityManager.class));
    }

    @After
    public void tearDown() {
        ShadowAccessibilityManager.reset();
    }

    @Test
    public void getAvailabilityStatus_noEnabledServices_shouldReturnUnsupported() {
        mAccessibilityManager.setEnabledAccessibilityServiceList(new ArrayList<>());
        AccessibilityUsagePreferenceController controller =
                new AccessibilityUsagePreferenceController(mContext, "test_key");

        assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
    }

    @Test
    public void getAvailabilityStatus_enabledServices_shouldReturnAvailableUnsearchable() {
        mAccessibilityManager.setEnabledAccessibilityServiceList(
                new ArrayList<>(Arrays.asList(new AccessibilityServiceInfo())));
        AccessibilityUsagePreferenceController controller =
                new AccessibilityUsagePreferenceController(mContext, "test_key");

        assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
    }
}