From 6c2f32b3ae7885dba08a612be792062b12ca4457 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Tue, 16 Jul 2019 17:45:46 +0800 Subject: [PATCH 1/8] Prevent accounts page directly opening in screen pinning mode In Settings there is no auth mechanism to prevent accounts page being opened in screen pinning mode. This CL makes it so that when users are trying to navigate to any pages in Settings from other apps in screen pinning mode, Settings app will directly close its page. Bug: 137015265 Bug: 135604684 Test: manual Change-Id: If26eda408a9ef6fa03ad82e5bee51bb7185950d6 Merged-In: If26eda408a9ef6fa03ad82e5bee51bb7185950d6 (cherry picked from commit f3242dab3546c019d4b79c502f7b8850d36123a5) --- .../android/settings/SettingsActivity.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index ea7874c6257..5c671206e98 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -277,6 +277,12 @@ public class SettingsActivity extends SettingsDrawerActivity @Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); + + if (isLockTaskModePinned() && !isSettingsRunOnTop()) { + Log.w(LOG_TAG, "Devices lock task mode pinned."); + finish(); + } + long startTime = System.currentTimeMillis(); final FeatureFactory factory = FeatureFactory.getFactory(this); @@ -939,4 +945,19 @@ public class SettingsActivity extends SettingsDrawerActivity return bitmap; } + + + private boolean isLockTaskModePinned() { + final ActivityManager activityManager = + getApplicationContext().getSystemService(ActivityManager.class); + return activityManager.getLockTaskModeState() == ActivityManager.LOCK_TASK_MODE_PINNED; + } + + private boolean isSettingsRunOnTop() { + final ActivityManager activityManager = + getApplicationContext().getSystemService(ActivityManager.class); + final String taskPkgName = activityManager.getRunningTasks(1 /* maxNum */) + .get(0 /* index */).baseActivity.getPackageName(); + return TextUtils.equals(getPackageName(), taskPkgName); + } } \ No newline at end of file From 3f4d3b4ac257451ccc1676f65321dedb2cb1870e Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Wed, 26 Feb 2020 23:55:51 +0800 Subject: [PATCH 2/8] RESTRICT AUTOMERGE Allow LockScreenPattern to be launched in the pinning screen If work profile lock is enabled and work app is pinned, users will get a black/white screen on the phone. That's because Settings is prevented from other apps launch any pages of Settings in the pinning mode. In order to launch some pages of Settings from other apps, we add a condition to the preventive mechanism and allow the activity inherited from SettingsBaseActivity to override the condition to have the activity to be launched from other apps in the pinning mode. Bug: 137015265 Bug: 135604684 Test: manual test Change-Id: I8070de79a83350d1658efcb19e983669dad0e673 Merged-In: I8070de79a83350d1658efcb19e983669dad0e673 --- .../settings/ConfirmDeviceCredentialBaseActivity.java | 5 +++++ src/com/android/settings/SettingsActivity.java | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java b/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java index d04014852d2..82e389d075b 100644 --- a/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java +++ b/src/com/android/settings/ConfirmDeviceCredentialBaseActivity.java @@ -129,6 +129,11 @@ public abstract class ConfirmDeviceCredentialBaseActivity extends SettingsActivi } } + @Override + public boolean isLaunchableInTaskModePinned() { + return true; + } + public void prepareEnterAnimation() { getFragment().prepareEnterAnimation(); } diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index 5c671206e98..80adec689a5 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -278,7 +278,7 @@ public class SettingsActivity extends SettingsDrawerActivity protected void onCreate(Bundle savedState) { super.onCreate(savedState); - if (isLockTaskModePinned() && !isSettingsRunOnTop()) { + if (isLockTaskModePinned() && !isSettingsRunOnTop() && !isLaunchableInTaskModePinned()) { Log.w(LOG_TAG, "Devices lock task mode pinned."); finish(); } @@ -946,6 +946,12 @@ public class SettingsActivity extends SettingsDrawerActivity return bitmap; } + /** + * @return whether or not the activity can be launched from other apps in the pinning screen. + */ + public boolean isLaunchableInTaskModePinned() { + return false; + } private boolean isLockTaskModePinned() { final ActivityManager activityManager = From 4b6e82fd5d2204cd37eae0d7c7b08f19b96baffe Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Mon, 11 May 2020 22:55:05 +0800 Subject: [PATCH 3/8] Allows to launch only authenticator owned activities - 3rd party developers can define himself-authenticator and use the accountPreferences attribute to load the predefined preference UI. - If a developer defines an action intent to launch the other activity in xml and it would return true due to the true exported attribute and no permission. - To avoid launching arbitrary activity. Here allows to launch only authenticator owned activities. Bug: 150946634 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=com.android.settings.accounts Test: PoC app Change-Id: I5ce1a0b3838db7b3fbe48c6ea23d5f093d625cdb Merged-In: I5ce1a0b3838db7b3fbe48c6ea23d5f093d625cdb (cherry picked from commit d6d8f988449617d757a5d7439314198d10d6ee78) --- .../settings/accounts/AccountTypePreferenceLoader.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java index 87aec14597f..7656dbbb77a 100644 --- a/src/com/android/settings/accounts/AccountTypePreferenceLoader.java +++ b/src/com/android/settings/accounts/AccountTypePreferenceLoader.java @@ -194,14 +194,7 @@ public class AccountTypePreferenceLoader { ActivityInfo resolvedActivityInfo = resolveInfo.activityInfo; ApplicationInfo resolvedAppInfo = resolvedActivityInfo.applicationInfo; try { - if (resolvedActivityInfo.exported) { - if (resolvedActivityInfo.permission == null) { - return true; // exported activity without permission. - } else if (pm.checkPermission(resolvedActivityInfo.permission, - authDesc.packageName) == PackageManager.PERMISSION_GRANTED) { - return true; - } - } + // Allows to launch only authenticator owned activities. ApplicationInfo authenticatorAppInf = pm.getApplicationInfo(authDesc.packageName, 0); return resolvedAppInfo.uid == authenticatorAppInf.uid; } catch (NameNotFoundException e) { From 3f5bf02fd8b72a57052fefccf90d0f42ab8ab5e0 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Thu, 14 May 2020 02:03:14 +0200 Subject: [PATCH 4/8] Prevent overlay drawing on top of Bluetooth pairing dialog Bug: 155648639 Change-Id: I99643ee9084f3a9bc1ad9a459ac27c587d832c91 Merged-In: I99643ee9084f3a9bc1ad9a459ac27c587d832c91 --- .../android/settings/bluetooth/BluetoothPairingDialog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java index 97382c3c480..599d2c96a57 100644 --- a/src/com/android/settings/bluetooth/BluetoothPairingDialog.java +++ b/src/com/android/settings/bluetooth/BluetoothPairingDialog.java @@ -26,6 +26,8 @@ import android.content.IntentFilter; import android.os.Bundle; import android.support.annotation.VisibleForTesting; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; + /** * BluetoothPairingDialog asks the user to enter a PIN / Passkey / simple confirmation * for pairing with a remote Bluetooth device. It is an activity that appears as a dialog. @@ -63,6 +65,8 @@ public class BluetoothPairingDialog extends Activity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + + getWindow().addPrivateFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); Intent intent = getIntent(); mBluetoothPairingController = new BluetoothPairingController(intent, this); // build the dialog fragment From ac671004231fb2ceb85f3101995e22dcc52c8088 Mon Sep 17 00:00:00 2001 From: Jakub Pawlowski Date: Thu, 14 May 2020 02:15:26 +0200 Subject: [PATCH 5/8] Prevent overlay drawing on top of Bluetooth discovery request dialog Bug: 155650356 Change-Id: I9cee6e5bb8cef77aa385d664fe0738db1496ef20 Merged-In: I9cee6e5bb8cef77aa385d664fe0738db1496ef20 --- .../android/settings/bluetooth/RequestPermissionActivity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/android/settings/bluetooth/RequestPermissionActivity.java b/src/com/android/settings/bluetooth/RequestPermissionActivity.java index d2e2060291f..7bc5c07f0ed 100644 --- a/src/com/android/settings/bluetooth/RequestPermissionActivity.java +++ b/src/com/android/settings/bluetooth/RequestPermissionActivity.java @@ -37,6 +37,8 @@ import com.android.settingslib.bluetooth.BluetoothDiscoverableTimeoutReceiver; import com.android.settingslib.bluetooth.LocalBluetoothAdapter; import com.android.settingslib.bluetooth.LocalBluetoothManager; +import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS; + /** * RequestPermissionActivity asks the user whether to enable discovery. This is * usually started by an application wanted to start bluetooth and or discovery @@ -72,6 +74,8 @@ public class RequestPermissionActivity extends Activity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + getWindow().addPrivateFlags(PRIVATE_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS); + setResult(Activity.RESULT_CANCELED); // Note: initializes mLocalAdapter and returns true on error From 573599b628a852fbe989f538af6928ee24f40f45 Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Thu, 2 Jul 2020 19:49:45 +0800 Subject: [PATCH 6/8] Enable the filterTouchesWhenObscured in Special app access - Enable the filterTouchesWhenObscured attribute on all toggle switches in all pages of the special app access Bug: 155288585 Test: make RunSettingsRoboTests Merged-In: I011cfe4b7e4e624a8338332ac47a353f7f3ab661 Merged-In: I85842db3faa558ea61bc878ca76ff6d8ce1a4b03 Change-Id: Id873bab7312226a9ea642a6241249c6754059a0b --- res/xml/app_ops_permissions_details.xml | 2 +- res/xml/external_sources_details.xml | 2 +- .../datausage/UnrestrictedDataAccess.java | 5 +- .../notification/ZenAccessSettings.java | 5 +- .../utils/ManagedServiceSettings.java | 7 ++- ...lterTouchesRestrictedSwitchPreference.java | 58 +++++++++++++++++++ .../widget/FilterTouchesSwitchPreference.java | 56 ++++++++++++++++++ 7 files changed, 126 insertions(+), 9 deletions(-) create mode 100644 src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java create mode 100644 src/com/android/settings/widget/FilterTouchesSwitchPreference.java diff --git a/res/xml/app_ops_permissions_details.xml b/res/xml/app_ops_permissions_details.xml index c36f44e917b..b9ef749e138 100644 --- a/res/xml/app_ops_permissions_details.xml +++ b/res/xml/app_ops_permissions_details.xml @@ -17,7 +17,7 @@ - - diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccess.java b/src/com/android/settings/datausage/UnrestrictedDataAccess.java index 58a34b91101..d408bc588c0 100644 --- a/src/com/android/settings/datausage/UnrestrictedDataAccess.java +++ b/src/com/android/settings/datausage/UnrestrictedDataAccess.java @@ -18,7 +18,6 @@ import android.app.Application; import android.content.Context; import android.os.Bundle; import android.os.UserHandle; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.view.Menu; @@ -34,6 +33,7 @@ import com.android.settings.applications.AppStateBaseBridge; import com.android.settings.applications.InstalledAppDetails; import com.android.settings.datausage.AppStateDataUsageBridge.DataUsageState; import com.android.settings.overlay.FeatureFactory; +import com.android.settings.widget.FilterTouchesSwitchPreference; import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState.AppEntry; import com.android.settingslib.applications.ApplicationsState.AppFilter; @@ -238,7 +238,8 @@ public class UnrestrictedDataAccess extends SettingsPreferenceFragment return app != null && UserHandle.isApp(app.info.uid); } - private class AccessPreference extends SwitchPreference implements DataSaverBackend.Listener { + private class AccessPreference extends FilterTouchesSwitchPreference implements + DataSaverBackend.Listener { private final AppEntry mEntry; private final DataUsageState mState; diff --git a/src/com/android/settings/notification/ZenAccessSettings.java b/src/com/android/settings/notification/ZenAccessSettings.java index a41a7339d0c..c325c78515a 100644 --- a/src/com/android/settings/notification/ZenAccessSettings.java +++ b/src/com/android/settings/notification/ZenAccessSettings.java @@ -35,7 +35,6 @@ import android.os.Handler; import android.os.Looper; import android.provider.Settings; import android.provider.Settings.Secure; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.support.v7.preference.PreferenceScreen; @@ -49,6 +48,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.overlay.FeatureFactory; +import com.android.settings.widget.FilterTouchesSwitchPreference; import java.util.ArrayList; import java.util.Collections; @@ -123,7 +123,8 @@ public class ZenAccessSettings extends EmptyTextSettings { for (ApplicationInfo app : apps) { final String pkg = app.packageName; final CharSequence label = app.loadLabel(mPkgMan); - final SwitchPreference pref = new SwitchPreference(getPrefContext()); + final FilterTouchesSwitchPreference pref = new FilterTouchesSwitchPreference( + getPrefContext()); pref.setPersistent(false); pref.setIcon(app.loadIcon(mPkgMan)); pref.setTitle(label); diff --git a/src/com/android/settings/utils/ManagedServiceSettings.java b/src/com/android/settings/utils/ManagedServiceSettings.java index 1dc6ae561fa..65d1e6e3d14 100644 --- a/src/com/android/settings/utils/ManagedServiceSettings.java +++ b/src/com/android/settings/utils/ManagedServiceSettings.java @@ -30,7 +30,6 @@ import android.content.pm.ServiceInfo; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.support.v7.preference.PreferenceScreen; @@ -41,6 +40,7 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.notification.EmptyTextSettings; +import com.android.settings.widget.FilterTouchesSwitchPreference; import java.util.Collections; import java.util.List; @@ -105,14 +105,15 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings { for (ServiceInfo service : services) { final ComponentName cn = new ComponentName(service.packageName, service.name); final String title = service.loadLabel(mPM).toString(); - final SwitchPreference pref = new SwitchPreference(getPrefContext()); + final FilterTouchesSwitchPreference pref = new FilterTouchesSwitchPreference( + getPrefContext()); pref.setPersistent(false); pref.setIcon(service.loadIcon(mPM)); pref.setTitle(title); pref.setChecked(mServiceListing.isEnabled(cn)); if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted( - service.packageName, managedProfileId)) { + service.packageName, managedProfileId)) { pref.setSummary(R.string.work_profile_notification_access_blocked_summary); } pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { diff --git a/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java b/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java new file mode 100644 index 00000000000..bd694bc388c --- /dev/null +++ b/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 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.widget; + +import android.content.Context; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; + +import com.android.settingslib.RestrictedSwitchPreference; + +/** + * This widget with enabled filterTouchesWhenObscured attribute use to replace + * the {@link RestrictedSwitchPreference} in the Special access app pages for + * security. + */ +public class FilterTouchesRestrictedSwitchPreference extends RestrictedSwitchPreference { + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, + int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FilterTouchesRestrictedSwitchPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + final View switchView = holder.findViewById(android.R.id.switch_widget); + if (switchView != null) { + final View rootView = switchView.getRootView(); + rootView.setFilterTouchesWhenObscured(true); + } + } +} diff --git a/src/com/android/settings/widget/FilterTouchesSwitchPreference.java b/src/com/android/settings/widget/FilterTouchesSwitchPreference.java new file mode 100644 index 00000000000..7ffa1965d67 --- /dev/null +++ b/src/com/android/settings/widget/FilterTouchesSwitchPreference.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 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.widget; + +import android.content.Context; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; + +/** + * This widget with enabled filterTouchesWhenObscured attribute use to replace + * the {@link SwitchPreference} in the Special access app pages for security. + */ +public class FilterTouchesSwitchPreference extends SwitchPreference { + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FilterTouchesSwitchPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + final View switchView = holder.findViewById(android.R.id.switch_widget); + if (switchView != null) { + final View rootView = switchView.getRootView(); + rootView.setFilterTouchesWhenObscured(true); + } + } +} From 7359b3840f06ef75c70d75a5708011fef25a2bab Mon Sep 17 00:00:00 2001 From: Sunny Shao Date: Thu, 2 Jul 2020 17:20:26 +0800 Subject: [PATCH 7/8] Enable the filterTouchesWhenObscured in Special app access - Enable the filterTouchesWhenObscured attribute on all toggle switches in all pages of the special app access Bug: 155288585 Test: make RunSettingsRoboTests Merged-In: I011cfe4b7e4e624a8338332ac47a353f7f3ab661 Change-Id: I85842db3faa558ea61bc878ca76ff6d8ce1a4b03 --- res/xml/app_ops_permissions_details.xml | 2 +- res/xml/external_sources_details.xml | 2 +- .../datausage/UnrestrictedDataAccess.java | 5 +- .../notification/ZenAccessSettings.java | 7 ++- .../utils/ManagedServiceSettings.java | 7 ++- ...lterTouchesRestrictedSwitchPreference.java | 58 +++++++++++++++++++ .../widget/FilterTouchesSwitchPreference.java | 56 ++++++++++++++++++ 7 files changed, 127 insertions(+), 10 deletions(-) create mode 100644 src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java create mode 100644 src/com/android/settings/widget/FilterTouchesSwitchPreference.java diff --git a/res/xml/app_ops_permissions_details.xml b/res/xml/app_ops_permissions_details.xml index c36f44e917b..b9ef749e138 100644 --- a/res/xml/app_ops_permissions_details.xml +++ b/res/xml/app_ops_permissions_details.xml @@ -17,7 +17,7 @@ - - diff --git a/src/com/android/settings/datausage/UnrestrictedDataAccess.java b/src/com/android/settings/datausage/UnrestrictedDataAccess.java index 58a34b91101..d408bc588c0 100644 --- a/src/com/android/settings/datausage/UnrestrictedDataAccess.java +++ b/src/com/android/settings/datausage/UnrestrictedDataAccess.java @@ -18,7 +18,6 @@ import android.app.Application; import android.content.Context; import android.os.Bundle; import android.os.UserHandle; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceViewHolder; import android.view.Menu; @@ -34,6 +33,7 @@ import com.android.settings.applications.AppStateBaseBridge; import com.android.settings.applications.InstalledAppDetails; import com.android.settings.datausage.AppStateDataUsageBridge.DataUsageState; import com.android.settings.overlay.FeatureFactory; +import com.android.settings.widget.FilterTouchesSwitchPreference; import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.applications.ApplicationsState.AppEntry; import com.android.settingslib.applications.ApplicationsState.AppFilter; @@ -238,7 +238,8 @@ public class UnrestrictedDataAccess extends SettingsPreferenceFragment return app != null && UserHandle.isApp(app.info.uid); } - private class AccessPreference extends SwitchPreference implements DataSaverBackend.Listener { + private class AccessPreference extends FilterTouchesSwitchPreference implements + DataSaverBackend.Listener { private final AppEntry mEntry; private final DataUsageState mState; diff --git a/src/com/android/settings/notification/ZenAccessSettings.java b/src/com/android/settings/notification/ZenAccessSettings.java index 238c11ec0e3..789a728e023 100644 --- a/src/com/android/settings/notification/ZenAccessSettings.java +++ b/src/com/android/settings/notification/ZenAccessSettings.java @@ -40,7 +40,6 @@ import android.os.Looper; import android.os.RemoteException; import android.provider.Settings; import android.provider.Settings.Secure; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.support.v7.preference.PreferenceScreen; @@ -55,6 +54,7 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.R; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.overlay.FeatureFactory; +import com.android.settings.widget.FilterTouchesSwitchPreference; import java.util.ArrayList; import java.util.Collections; @@ -135,7 +135,8 @@ public class ZenAccessSettings extends EmptyTextSettings { for (ApplicationInfo app : apps) { final String pkg = app.packageName; final CharSequence label = app.loadLabel(mPkgMan); - final SwitchPreference pref = new SwitchPreference(getPrefContext()); + final FilterTouchesSwitchPreference pref = new FilterTouchesSwitchPreference( + getPrefContext()); pref.setPersistent(false); pref.setIcon(app.loadIcon(mPkgMan)); pref.setTitle(label); @@ -179,7 +180,7 @@ public class ZenAccessSettings extends EmptyTextSettings { requestingPackages.add(info.packageName); } } - } catch(RemoteException e) { + } catch (RemoteException e) { Log.e(TAG, "Cannot reach packagemanager", e); } return requestingPackages; diff --git a/src/com/android/settings/utils/ManagedServiceSettings.java b/src/com/android/settings/utils/ManagedServiceSettings.java index 7a888dbabda..55c20473753 100644 --- a/src/com/android/settings/utils/ManagedServiceSettings.java +++ b/src/com/android/settings/utils/ManagedServiceSettings.java @@ -33,7 +33,6 @@ import android.content.pm.ServiceInfo; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; -import android.support.v14.preference.SwitchPreference; import android.support.v7.preference.Preference; import android.support.v7.preference.Preference.OnPreferenceChangeListener; import android.support.v7.preference.PreferenceScreen; @@ -46,6 +45,7 @@ import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.core.instrumentation.InstrumentedDialogFragment; import com.android.settings.notification.EmptyTextSettings; +import com.android.settings.widget.FilterTouchesSwitchPreference; import java.util.Collections; import java.util.List; @@ -127,7 +127,8 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings { Log.e(TAG, "can't find package name", e); } final String summary = service.loadLabel(mPm).toString(); - final SwitchPreference pref = new SwitchPreference(getPrefContext()); + final FilterTouchesSwitchPreference pref = new FilterTouchesSwitchPreference( + getPrefContext()); pref.setPersistent(false); pref.setIcon(mIconDrawableFactory.getBadgedIcon(service, service.applicationInfo, UserHandle.getUserId(service.applicationInfo.uid))); @@ -141,7 +142,7 @@ public abstract class ManagedServiceSettings extends EmptyTextSettings { pref.setChecked(isServiceEnabled(cn)); if (managedProfileId != UserHandle.USER_NULL && !mDpm.isNotificationListenerServicePermitted( - service.packageName, managedProfileId)) { + service.packageName, managedProfileId)) { pref.setSummary(R.string.work_profile_notification_access_blocked_summary); } pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { diff --git a/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java b/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java new file mode 100644 index 00000000000..bd694bc388c --- /dev/null +++ b/src/com/android/settings/widget/FilterTouchesRestrictedSwitchPreference.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2020 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.widget; + +import android.content.Context; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; + +import com.android.settingslib.RestrictedSwitchPreference; + +/** + * This widget with enabled filterTouchesWhenObscured attribute use to replace + * the {@link RestrictedSwitchPreference} in the Special access app pages for + * security. + */ +public class FilterTouchesRestrictedSwitchPreference extends RestrictedSwitchPreference { + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs, + int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public FilterTouchesRestrictedSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FilterTouchesRestrictedSwitchPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + final View switchView = holder.findViewById(android.R.id.switch_widget); + if (switchView != null) { + final View rootView = switchView.getRootView(); + rootView.setFilterTouchesWhenObscured(true); + } + } +} diff --git a/src/com/android/settings/widget/FilterTouchesSwitchPreference.java b/src/com/android/settings/widget/FilterTouchesSwitchPreference.java new file mode 100644 index 00000000000..7ffa1965d67 --- /dev/null +++ b/src/com/android/settings/widget/FilterTouchesSwitchPreference.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2020 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.widget; + +import android.content.Context; +import android.support.v14.preference.SwitchPreference; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; + +/** + * This widget with enabled filterTouchesWhenObscured attribute use to replace + * the {@link SwitchPreference} in the Special access app pages for security. + */ +public class FilterTouchesSwitchPreference extends SwitchPreference { + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public FilterTouchesSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public FilterTouchesSwitchPreference(Context context) { + super(context); + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + final View switchView = holder.findViewById(android.R.id.switch_widget); + if (switchView != null) { + final View rootView = switchView.getRootView(); + rootView.setFilterTouchesWhenObscured(true); + } + } +} From ca90cd36151f541458c2dce55600456622694349 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 31 Jul 2020 13:15:35 -0400 Subject: [PATCH 8/8] Allow DND screens on low ram devices Low RAM devices are allowed to use NLSs and CPSs in Android 11. Test: this, ConditionProviderVerifierActivity (cts) Bug: 161471776 Change-Id: Ic97f68dd3721ff50f31d81f0afa9f9a1c2c08e86 --- .../zenaccess/ZenAccessController.java | 9 +-------- .../zenaccess/ZenAccessDetails.java | 3 --- .../ZenAccessSettingObserverMixin.java | 6 ------ .../zenaccess/ZenAccessControllerTest.java | 6 ------ .../ZenAccessSettingObserverMixinTest.java | 20 +------------------ 5 files changed, 2 insertions(+), 42 deletions(-) diff --git a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java index 727870c6d60..e6b389a5b3c 100644 --- a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java +++ b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessController.java @@ -40,20 +40,13 @@ public class ZenAccessController extends BasePreferenceController { private static final String TAG = "ZenAccessController"; - private final ActivityManager mActivityManager; - public ZenAccessController(Context context, String preferenceKey) { super(context, preferenceKey); - mActivityManager = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE); } @Override public int getAvailabilityStatus() { - return isSupported(mActivityManager) ? AVAILABLE : UNSUPPORTED_ON_DEVICE; - } - - public static boolean isSupported(ActivityManager activityManager) { - return !activityManager.isLowRamDevice(); + return AVAILABLE; } public static Set getPackagesRequestingNotificationPolicyAccess() { diff --git a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessDetails.java b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessDetails.java index a18e7d63cad..ba6bb1dfc83 100644 --- a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessDetails.java +++ b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessDetails.java @@ -50,9 +50,6 @@ public class ZenAccessDetails extends AppInfoWithHeader implements @Override protected boolean refreshUi() { final Context context = getContext(); - if (!ZenAccessController.isSupported(context.getSystemService(ActivityManager.class))) { - return false; - } // If this app didn't declare this permission in their manifest, don't bother showing UI. final Set needAccessApps = ZenAccessController.getPackagesRequestingNotificationPolicyAccess(); diff --git a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixin.java b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixin.java index 30507efffa9..da238f62496 100644 --- a/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixin.java +++ b/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixin.java @@ -53,9 +53,6 @@ public class ZenAccessSettingObserverMixin extends ContentObserver implements Li @Override public void onStart() { - if (!ZenAccessController.isSupported(mContext.getSystemService(ActivityManager.class))) { - return; - } mContext.getContentResolver().registerContentObserver( Settings.Secure.getUriFor( Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), @@ -69,9 +66,6 @@ public class ZenAccessSettingObserverMixin extends ContentObserver implements Li @Override public void onStop() { - if (!ZenAccessController.isSupported(mContext.getSystemService(ActivityManager.class))) { - return; - } mContext.getContentResolver().unregisterContentObserver(this /* observer */); } } diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessControllerTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessControllerTest.java index 6041e9dead1..8febbc68bae 100644 --- a/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessControllerTest.java +++ b/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessControllerTest.java @@ -62,12 +62,6 @@ public class ZenAccessControllerTest { assertThat(mController.isAvailable()).isTrue(); } - @Test - public void isAvailable_lowMemory_false() { - mActivityManager.setIsLowRamDevice(true); - assertThat(mController.isAvailable()).isFalse(); - } - @Test public void logSpecialPermissionChange() { ZenAccessController.logSpecialPermissionChange(true, "app", mContext); diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixinTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixinTest.java index cba1a5199ed..fb565b62e9e 100644 --- a/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixinTest.java +++ b/tests/robotests/src/com/android/settings/applications/specialaccess/zenaccess/ZenAccessSettingObserverMixinTest.java @@ -65,27 +65,13 @@ public class ZenAccessSettingObserverMixinTest { } @Test - public void onStart_lowMemory_shouldNotRegisterListener() { + public void onStart_shouldRegisterListener() { final ShadowActivityManager sam = Shadow.extract( mContext.getSystemService(ActivityManager.class)); sam.setIsLowRamDevice(true); mLifecycle.handleLifecycleEvent(ON_START); - mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor( - Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null); - - verify(mListener, never()).onZenAccessPolicyChanged(); - } - - @Test - public void onStart_highMemory_shouldRegisterListener() { - final ShadowActivityManager sam = Shadow.extract( - mContext.getSystemService(ActivityManager.class)); - sam.setIsLowRamDevice(false); - - mLifecycle.handleLifecycleEvent(ON_START); - mContext.getContentResolver().notifyChange(Settings.Secure.getUriFor( Settings.Secure.ENABLED_NOTIFICATION_POLICY_ACCESS_PACKAGES), null); @@ -94,10 +80,6 @@ public class ZenAccessSettingObserverMixinTest { @Test public void onStop_shouldUnregisterListener() { - final ShadowActivityManager sam = Shadow.extract( - mContext.getSystemService(ActivityManager.class)); - sam.setIsLowRamDevice(false); - mLifecycle.handleLifecycleEvent(ON_START); mLifecycle.handleLifecycleEvent(ON_STOP);