Disable managed services special access screens...
... on low ram devices. - Remove them from the 'Special app access' screen - Display an error message if an app intents directly to them Bug: 35219985 Test: visual, and runtest --path ManagedAccessSettingsLowRamTest.java, when the device is in low ram mode and when it's not. Change-Id: Ied919cb248ae56683a00e3492c4737dfd00449ac
This commit is contained in:
@@ -2511,6 +2511,16 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$SpecialAccessSettingsActivity"
|
||||
android:taskAffinity="">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
|
||||
android:value="com.android.settings.applications.SpecialAccessSettings" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="Settings$NotificationAccessSettingsActivity"
|
||||
android:label="@string/manage_notification_access_title"
|
||||
android:taskAffinity="">
|
||||
|
@@ -8963,4 +8963,7 @@
|
||||
|
||||
<!-- The divider symbol between different parts of the notification header including spaces. not translatable [CHAR LIMIT=3] -->
|
||||
<string name="notification_header_divider_symbol_with_spaces" translatable="false">" • "</string>
|
||||
|
||||
<!-- Note displayed when certain features are not available on low ram devices. [CHAR LIMIT=NONE] -->
|
||||
<string name="disabled_low_ram_device">This feature is not available on this device</string>
|
||||
</resources>
|
||||
|
@@ -70,8 +70,12 @@
|
||||
|
||||
<Preference
|
||||
android:key="special_access"
|
||||
android:fragment="com.android.settings.applications.SpecialAccessSettings"
|
||||
android:title="@string/special_access"
|
||||
android:order="20" />
|
||||
android:order="20" >
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.settings"
|
||||
android:targetClass="com.android.settings.Settings$SpecialAccessSettingsActivity" />
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
@@ -98,6 +98,7 @@ public class Settings extends SettingsActivity {
|
||||
public static class DreamSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class NotificationStationActivity extends SettingsActivity { /* empty */ }
|
||||
public static class UserSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class SpecialAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class NotificationAccessSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class VrListenersSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
public static class PictureInPictureSettingsActivity extends SettingsActivity { /* empty */ }
|
||||
|
@@ -14,8 +14,11 @@
|
||||
|
||||
package com.android.settings.applications;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
@@ -31,6 +34,9 @@ public class SpecialAccessSettings extends DashboardFragment {
|
||||
|
||||
private static final String TAG = "SpecialAccessSettings";
|
||||
|
||||
private static final String[] DISABLED_FEATURES_LOW_RAM =
|
||||
new String[] {"notification_access", "zen_access", "enabled_vr_listeners"};
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
@@ -41,6 +47,20 @@ public class SpecialAccessSettings extends DashboardFragment {
|
||||
return R.xml.special_access;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
|
||||
if (ActivityManager.isLowRamDeviceStatic()) {
|
||||
for (String disabledFeature : DISABLED_FEATURES_LOW_RAM) {
|
||||
Preference pref = findPreference(disabledFeature);
|
||||
if (pref != null) {
|
||||
removePreference(disabledFeature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<PreferenceController> getPreferenceControllers(Context context) {
|
||||
return null;
|
||||
|
@@ -53,6 +53,7 @@ import com.android.settings.applications.PictureInPictureDetails;
|
||||
import com.android.settings.applications.PictureInPictureSettings;
|
||||
import com.android.settings.applications.ProcessStatsSummary;
|
||||
import com.android.settings.applications.ProcessStatsUi;
|
||||
import com.android.settings.applications.SpecialAccessSettings;
|
||||
import com.android.settings.applications.UsageAccessDetails;
|
||||
import com.android.settings.applications.VrListenerSettings;
|
||||
import com.android.settings.applications.WriteSettingsDetails;
|
||||
@@ -189,6 +190,7 @@ public class SettingsGateway {
|
||||
DataUsageSummary.class.getName(),
|
||||
DreamSettings.class.getName(),
|
||||
UserSettings.class.getName(),
|
||||
SpecialAccessSettings.class.getName(),
|
||||
NotificationAccessSettings.class.getName(),
|
||||
ZenAccessSettings.class.getName(),
|
||||
PrintSettingsFragment.class.getName(),
|
||||
|
@@ -16,21 +16,18 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
@@ -92,6 +92,7 @@ public class ZenAccessSettings extends EmptyTextSettings {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (!ActivityManager.isLowRamDeviceStatic()) {
|
||||
reloadList();
|
||||
getContentResolver().registerContentObserver(
|
||||
Secure.getUriFor(Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), false,
|
||||
@@ -99,13 +100,18 @@ public class ZenAccessSettings extends EmptyTextSettings {
|
||||
getContentResolver().registerContentObserver(
|
||||
Secure.getUriFor(Secure.ENABLED_NOTIFICATION_LISTENERS), false,
|
||||
mObserver);
|
||||
} else {
|
||||
setEmptyText(R.string.disabled_low_ram_device);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if (!ActivityManager.isLowRamDeviceStatic()) {
|
||||
getContentResolver().unregisterContentObserver(mObserver);
|
||||
}
|
||||
}
|
||||
|
||||
private void reloadList() {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.utils;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.Fragment;
|
||||
@@ -91,8 +92,12 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (!ActivityManager.isLowRamDeviceStatic()) {
|
||||
mServiceListing.reload();
|
||||
mServiceListing.setListening(true);
|
||||
} else {
|
||||
setEmptyText(R.string.disabled_low_ram_device);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -230,7 +235,6 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings {
|
||||
public static class Config {
|
||||
public String tag;
|
||||
public String setting;
|
||||
public String secondarySetting;
|
||||
public String intentAction;
|
||||
public String permission;
|
||||
public String noun;
|
||||
|
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Instrumentation;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.filters.SmallTest;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@SmallTest
|
||||
public class ManagedAccessSettingsLowRamTest {
|
||||
|
||||
private Instrumentation mInstrumentation;
|
||||
private Context mTargetContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mInstrumentation = InstrumentationRegistry.getInstrumentation();
|
||||
mTargetContext = mInstrumentation.getTargetContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManagedAccessOptionsVisibility() throws Exception {
|
||||
mInstrumentation.startActivitySync(new Intent(mTargetContext,
|
||||
com.android.settings.Settings.SpecialAccessSettingsActivity.class));
|
||||
|
||||
String[] managedServiceLabels = new String[] {"Do Not Disturb access",
|
||||
"VR helper services", "Notification access"};
|
||||
for (String label : managedServiceLabels) {
|
||||
if (ActivityManager.isLowRamDeviceStatic()) {
|
||||
onView(withText(label)).check(doesNotExist());
|
||||
} else {
|
||||
onView(withText(label)).check(matches(isDisplayed()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchNotificationSetting_onlyWorksIfNotLowRam() {
|
||||
final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
||||
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
final String label = "This feature is not available on this device";
|
||||
if (ActivityManager.isLowRamDeviceStatic()) {
|
||||
onView(withText(label)).check(matches(isDisplayed()));
|
||||
} else {
|
||||
onView(withText(label)).check(doesNotExist());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchDndSetting_onlyWorksIfNotLowRam() {
|
||||
final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
|
||||
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
final String label = "This feature is not available on this device";
|
||||
if (ActivityManager.isLowRamDeviceStatic()) {
|
||||
onView(withText(label)).check(matches(isDisplayed()));
|
||||
} else {
|
||||
onView(withText(label)).check(doesNotExist());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchVrSetting_onlyWorksIfNotLowRam() {
|
||||
final Intent intent = new Intent(Settings.ACTION_VR_LISTENER_SETTINGS);
|
||||
|
||||
mInstrumentation.startActivitySync(intent);
|
||||
|
||||
final String label = "This feature is not available on this device";
|
||||
if (ActivityManager.isLowRamDeviceStatic()) {
|
||||
onView(withText(label)).check(matches(isDisplayed()));
|
||||
} else {
|
||||
onView(withText(label)).check(doesNotExist());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user