From 4fe66437a8721f4e7c883806a51e4bac68156559 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Thu, 18 Feb 2021 17:18:20 +0000 Subject: [PATCH 01/17] Revert "Use location access for recent location apps." This reverts commit f383cb44b4b23c13cc0a25ea823dac786238ebc0. Reason for revert: crashes on work profiles (http://b/180516388) Change-Id: Iff499e6a1439b6ecb524a61a9a88fe253799a131 (cherry picked from commit 5da4f381a60d60d528b2c5c3a8baf43a71caf26e) --- res/xml/location_settings.xml | 14 +- res/xml/location_settings_personal.xml | 10 +- res/xml/location_settings_workprofile.xml | 12 +- .../settings/location/LocationSettings.java | 2 +- .../location/LocationWorkProfileSettings.java | 7 +- ...entLocationAccessPreferenceController.java | 189 ++++++++---------- ...ocationAccessPreferenceControllerTest.java | 62 +++++- 7 files changed, 166 insertions(+), 130 deletions(-) diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 162dc389824..fb03f4c7f3d 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -22,10 +22,16 @@ settings:keywords="@string/keywords_location"> + android:key="recent_location_requests" + android:title="@string/location_category_recent_location_requests" + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + recentLocationAccesses = new ArrayList<>(); - final UserManager userManager = UserManager.get(mContext); - for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted()) { - if (isRequestMatchesProfileType(userManager, access, mType)) { - recentLocationAccesses.add(access); - } - } - - if (recentLocationAccesses.size() > 0) { - // Add preferences to container in original order (already sorted by recency). - for (RecentLocationAccesses.Access access : recentLocationAccesses) { - mCategoryRecentLocationRequests.addPreference( - createAppPreference(prefContext, access, mFragment)); - } - } else { - // If there's no item to display, add a "No recent apps" item. - final Preference banner = new AppPreference(prefContext); - banner.setTitle(R.string.location_no_recent_accesses); - banner.setSelectable(false); - mCategoryRecentLocationRequests.addPreference(banner); - } + final LayoutPreference preference = screen.findPreference(KEY_APPS_DASHBOARD); + final View view = preference.findViewById(R.id.app_entities_header); + mController = AppEntitiesHeaderController.newInstance(mContext, view) + .setHeaderTitleRes(R.string.location_category_recent_location_access) + .setHeaderDetailsRes(R.string.location_recent_location_access_view_details) + .setHeaderEmptyRes(R.string.location_no_recent_accesses) + .setHeaderDetailsClickListener((View v) -> { + final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE); + intent.putExtra(Intent.EXTRA_PERMISSION_NAME, + Manifest.permission.ACCESS_FINE_LOCATION); + intent.putExtra(Intent.EXTRA_DURATION_MILLIS, DAYS.toMillis(1)); + mContext.startActivity(intent); + }); } @Override - public void onLocationModeChanged(int mode, boolean restricted) { - mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); + public void updateState(Preference preference) { + updateRecentApps(); } - /** - * Initialize {@link ProfileSelectFragment.ProfileType} of the controller - * - * @param type {@link ProfileSelectFragment.ProfileType} of the controller. - */ - public void setProfileType(@ProfileSelectFragment.ProfileType int type) { - mType = type; - } - - /** - * Create a {@link AppPreference} - */ - public static AppPreference createAppPreference(Context prefContext, - RecentLocationAccesses.Access access, DashboardFragment fragment) { - final AppPreference pref = new AppPreference(prefContext); - pref.setIcon(access.icon); - pref.setTitle(access.label); - pref.setOnPreferenceClickListener(new PackageEntryClickedListener( - fragment.getContext(), access.packageName, access.userHandle)); - return pref; - } - - /** - * Return if the {@link RecentLocationAccesses.Access} matches current UI - * {@ProfileSelectFragment.ProfileType} - */ - public static boolean isRequestMatchesProfileType(UserManager userManager, - RecentLocationAccesses.Access access, @ProfileSelectFragment.ProfileType int type) { - - final boolean isWorkProfile = userManager.isManagedProfile( - access.userHandle.getIdentifier()); - if (isWorkProfile && (type & ProfileSelectFragment.ProfileType.WORK) != 0) { - return true; + private void updateRecentApps() { + final List recentLocationAccesses = + mRecentLocationAccesses.getAppListSorted(); + if (recentLocationAccesses.size() > 0) { + // Display the top 3 preferences to container in original order. + int i = 0; + for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) { + final RecentLocationAccesses.Access access = recentLocationAccesses.get(i); + final AppEntityInfo appEntityInfo = new AppEntityInfo.Builder() + .setIcon(access.icon) + .setTitle(access.label) + .setSummary(StringUtil.formatRelativeTime(mContext, + System.currentTimeMillis() - access.accessFinishTime, false, + RelativeDateTimeFormatter.Style.SHORT)) + .setOnClickListener((v) -> { + final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION); + intent.putExtra(Intent.EXTRA_PERMISSION_NAME, + Manifest.permission.ACCESS_FINE_LOCATION); + intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName); + intent.putExtra(Intent.EXTRA_USER, access.userHandle); + mContext.startActivity(intent); + }) + .build(); + mController.setAppEntity(i, appEntityInfo); + } + for (; i < MAXIMUM_APP_COUNT; i++) { + mController.removeAppEntity(i); + } } - if (!isWorkProfile && (type & ProfileSelectFragment.ProfileType.PERSONAL) != 0) { - return true; - } - return false; + mController.apply(); } } diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java index 5feee6002e0..71a80de0689 100644 --- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java @@ -24,17 +24,19 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.graphics.drawable.Drawable; +import android.provider.DeviceConfig; import android.view.LayoutInflater; import android.view.View; +import android.widget.ImageView; import android.widget.TextView; -import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.Utils; import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settingslib.location.RecentLocationAccesses; +import com.android.settingslib.widget.LayoutPreference; import org.junit.After; import org.junit.Before; @@ -53,14 +55,11 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowDeviceConfig.class}) public class RecentLocationAccessPreferenceControllerTest { - private static final String PREFERENCE_KEY = "test_preference_key"; @Mock - private PreferenceCategory mLayoutPreference; + private LayoutPreference mLayoutPreference; @Mock private PreferenceScreen mScreen; @Mock - private DashboardFragment mDashboardFragment; - @Mock private RecentLocationAccesses mRecentLocationApps; private Context mContext; @@ -72,16 +71,15 @@ public class RecentLocationAccessPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); mController = spy( - new RecentLocationAccessPreferenceController(mContext, PREFERENCE_KEY, - mRecentLocationApps)); - mController.init(mDashboardFragment); + new RecentLocationAccessPreferenceController(mContext, mRecentLocationApps)); final String key = mController.getPreferenceKey(); mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate( R.layout.app_entities_header, null /* root */); when(mScreen.findPreference(key)).thenReturn(mLayoutPreference); when(mLayoutPreference.getKey()).thenReturn(key); when(mLayoutPreference.getContext()).thenReturn(mContext); - when(mDashboardFragment.getContext()).thenReturn(mContext); + when(mLayoutPreference.findViewById(R.id.app_entities_header)).thenReturn( + mAppEntitiesHeaderView); } @After @@ -90,7 +88,16 @@ public class RecentLocationAccessPreferenceControllerTest { } @Test - public void isAvailable_shouldReturnTrue() { + public void isAvailable_permissionHubNotSet_shouldReturnFalse() { + // We have not yet set the property to show the Permissions Hub. + assertThat(mController.isAvailable()).isEqualTo(false); + } + + @Test + public void isAvailable_permissionHubEnabled_shouldReturnTrue() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true); + assertThat(mController.isAvailable()).isEqualTo(true); } @@ -111,6 +118,39 @@ public class RecentLocationAccessPreferenceControllerTest { assertThat(details.hasOnClickListeners()).isTrue(); } + @Test + public void updateState_whenAppListMoreThanThree_shouldDisplayTopThreeApps() { + final List accesses = createMockAccesses(6); + doReturn(accesses).when(mRecentLocationApps).getAppListSorted(); + mController.displayPreference(mScreen); + mController.updateState(mLayoutPreference); + + // The widget can display the top 3 apps from the list when there're more than 3. + final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view); + final ImageView appIconView1 = app1View.findViewById(R.id.app_icon); + final TextView appTitle1 = app1View.findViewById(R.id.app_title); + + assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView1.getDrawable()).isNotNull(); + assertThat(appTitle1.getText()).isEqualTo("appTitle0"); + + final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view); + final ImageView appIconView2 = app2View.findViewById(R.id.app_icon); + final TextView appTitle2 = app2View.findViewById(R.id.app_title); + + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView2.getDrawable()).isNotNull(); + assertThat(appTitle2.getText()).isEqualTo("appTitle1"); + + final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view); + final ImageView appIconView3 = app3View.findViewById(R.id.app_icon); + final TextView appTitle3 = app3View.findViewById(R.id.app_title); + + assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView3.getDrawable()).isNotNull(); + assertThat(appTitle3.getText()).isEqualTo("appTitle2"); + } + private List createMockAccesses(int count) { final List accesses = new ArrayList<>(); for (int i = 0; i < count; i++) { From 2bd17b2f316931486ee786ca8a19154c0f0f69c4 Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Thu, 18 Feb 2021 17:18:20 +0000 Subject: [PATCH 02/17] Revert "Use location access for recent location apps." This reverts commit f383cb44b4b23c13cc0a25ea823dac786238ebc0. Reason for revert: crashes on work profiles (http://b/180516388) Change-Id: Iff499e6a1439b6ecb524a61a9a88fe253799a131 (cherry picked from commit 5da4f381a60d60d528b2c5c3a8baf43a71caf26e) --- res/xml/location_settings.xml | 14 +- res/xml/location_settings_personal.xml | 10 +- res/xml/location_settings_workprofile.xml | 12 +- .../settings/location/LocationSettings.java | 2 +- .../location/LocationWorkProfileSettings.java | 7 +- ...entLocationAccessPreferenceController.java | 189 ++++++++---------- ...ocationAccessPreferenceControllerTest.java | 62 +++++- 7 files changed, 166 insertions(+), 130 deletions(-) diff --git a/res/xml/location_settings.xml b/res/xml/location_settings.xml index 162dc389824..fb03f4c7f3d 100644 --- a/res/xml/location_settings.xml +++ b/res/xml/location_settings.xml @@ -22,10 +22,16 @@ settings:keywords="@string/keywords_location"> + android:key="recent_location_requests" + android:title="@string/location_category_recent_location_requests" + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + + settings:controller="com.android.settings.location.RecentLocationRequestPreferenceController"/> + + recentLocationAccesses = new ArrayList<>(); - final UserManager userManager = UserManager.get(mContext); - for (RecentLocationAccesses.Access access : mRecentLocationApps.getAppListSorted()) { - if (isRequestMatchesProfileType(userManager, access, mType)) { - recentLocationAccesses.add(access); - } - } - - if (recentLocationAccesses.size() > 0) { - // Add preferences to container in original order (already sorted by recency). - for (RecentLocationAccesses.Access access : recentLocationAccesses) { - mCategoryRecentLocationRequests.addPreference( - createAppPreference(prefContext, access, mFragment)); - } - } else { - // If there's no item to display, add a "No recent apps" item. - final Preference banner = new AppPreference(prefContext); - banner.setTitle(R.string.location_no_recent_accesses); - banner.setSelectable(false); - mCategoryRecentLocationRequests.addPreference(banner); - } + final LayoutPreference preference = screen.findPreference(KEY_APPS_DASHBOARD); + final View view = preference.findViewById(R.id.app_entities_header); + mController = AppEntitiesHeaderController.newInstance(mContext, view) + .setHeaderTitleRes(R.string.location_category_recent_location_access) + .setHeaderDetailsRes(R.string.location_recent_location_access_view_details) + .setHeaderEmptyRes(R.string.location_no_recent_accesses) + .setHeaderDetailsClickListener((View v) -> { + final Intent intent = new Intent(Intent.ACTION_REVIEW_PERMISSION_USAGE); + intent.putExtra(Intent.EXTRA_PERMISSION_NAME, + Manifest.permission.ACCESS_FINE_LOCATION); + intent.putExtra(Intent.EXTRA_DURATION_MILLIS, DAYS.toMillis(1)); + mContext.startActivity(intent); + }); } @Override - public void onLocationModeChanged(int mode, boolean restricted) { - mCategoryRecentLocationRequests.setEnabled(mLocationEnabler.isEnabled(mode)); + public void updateState(Preference preference) { + updateRecentApps(); } - /** - * Initialize {@link ProfileSelectFragment.ProfileType} of the controller - * - * @param type {@link ProfileSelectFragment.ProfileType} of the controller. - */ - public void setProfileType(@ProfileSelectFragment.ProfileType int type) { - mType = type; - } - - /** - * Create a {@link AppPreference} - */ - public static AppPreference createAppPreference(Context prefContext, - RecentLocationAccesses.Access access, DashboardFragment fragment) { - final AppPreference pref = new AppPreference(prefContext); - pref.setIcon(access.icon); - pref.setTitle(access.label); - pref.setOnPreferenceClickListener(new PackageEntryClickedListener( - fragment.getContext(), access.packageName, access.userHandle)); - return pref; - } - - /** - * Return if the {@link RecentLocationAccesses.Access} matches current UI - * {@ProfileSelectFragment.ProfileType} - */ - public static boolean isRequestMatchesProfileType(UserManager userManager, - RecentLocationAccesses.Access access, @ProfileSelectFragment.ProfileType int type) { - - final boolean isWorkProfile = userManager.isManagedProfile( - access.userHandle.getIdentifier()); - if (isWorkProfile && (type & ProfileSelectFragment.ProfileType.WORK) != 0) { - return true; + private void updateRecentApps() { + final List recentLocationAccesses = + mRecentLocationAccesses.getAppListSorted(); + if (recentLocationAccesses.size() > 0) { + // Display the top 3 preferences to container in original order. + int i = 0; + for (; i < Math.min(recentLocationAccesses.size(), MAXIMUM_APP_COUNT); i++) { + final RecentLocationAccesses.Access access = recentLocationAccesses.get(i); + final AppEntityInfo appEntityInfo = new AppEntityInfo.Builder() + .setIcon(access.icon) + .setTitle(access.label) + .setSummary(StringUtil.formatRelativeTime(mContext, + System.currentTimeMillis() - access.accessFinishTime, false, + RelativeDateTimeFormatter.Style.SHORT)) + .setOnClickListener((v) -> { + final Intent intent = new Intent(Intent.ACTION_MANAGE_APP_PERMISSION); + intent.putExtra(Intent.EXTRA_PERMISSION_NAME, + Manifest.permission.ACCESS_FINE_LOCATION); + intent.putExtra(Intent.EXTRA_PACKAGE_NAME, access.packageName); + intent.putExtra(Intent.EXTRA_USER, access.userHandle); + mContext.startActivity(intent); + }) + .build(); + mController.setAppEntity(i, appEntityInfo); + } + for (; i < MAXIMUM_APP_COUNT; i++) { + mController.removeAppEntity(i); + } } - if (!isWorkProfile && (type & ProfileSelectFragment.ProfileType.PERSONAL) != 0) { - return true; - } - return false; + mController.apply(); } } diff --git a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java index 5feee6002e0..71a80de0689 100644 --- a/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/location/RecentLocationAccessPreferenceControllerTest.java @@ -24,17 +24,19 @@ import static org.mockito.Mockito.when; import android.content.Context; import android.graphics.drawable.Drawable; +import android.provider.DeviceConfig; import android.view.LayoutInflater; import android.view.View; +import android.widget.ImageView; import android.widget.TextView; -import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceScreen; import com.android.settings.R; -import com.android.settings.dashboard.DashboardFragment; +import com.android.settings.Utils; import com.android.settings.testutils.shadow.ShadowDeviceConfig; import com.android.settingslib.location.RecentLocationAccesses; +import com.android.settingslib.widget.LayoutPreference; import org.junit.After; import org.junit.Before; @@ -53,14 +55,11 @@ import java.util.List; @RunWith(RobolectricTestRunner.class) @Config(shadows = {ShadowDeviceConfig.class}) public class RecentLocationAccessPreferenceControllerTest { - private static final String PREFERENCE_KEY = "test_preference_key"; @Mock - private PreferenceCategory mLayoutPreference; + private LayoutPreference mLayoutPreference; @Mock private PreferenceScreen mScreen; @Mock - private DashboardFragment mDashboardFragment; - @Mock private RecentLocationAccesses mRecentLocationApps; private Context mContext; @@ -72,16 +71,15 @@ public class RecentLocationAccessPreferenceControllerTest { MockitoAnnotations.initMocks(this); mContext = spy(RuntimeEnvironment.application); mController = spy( - new RecentLocationAccessPreferenceController(mContext, PREFERENCE_KEY, - mRecentLocationApps)); - mController.init(mDashboardFragment); + new RecentLocationAccessPreferenceController(mContext, mRecentLocationApps)); final String key = mController.getPreferenceKey(); mAppEntitiesHeaderView = LayoutInflater.from(mContext).inflate( R.layout.app_entities_header, null /* root */); when(mScreen.findPreference(key)).thenReturn(mLayoutPreference); when(mLayoutPreference.getKey()).thenReturn(key); when(mLayoutPreference.getContext()).thenReturn(mContext); - when(mDashboardFragment.getContext()).thenReturn(mContext); + when(mLayoutPreference.findViewById(R.id.app_entities_header)).thenReturn( + mAppEntitiesHeaderView); } @After @@ -90,7 +88,16 @@ public class RecentLocationAccessPreferenceControllerTest { } @Test - public void isAvailable_shouldReturnTrue() { + public void isAvailable_permissionHubNotSet_shouldReturnFalse() { + // We have not yet set the property to show the Permissions Hub. + assertThat(mController.isAvailable()).isEqualTo(false); + } + + @Test + public void isAvailable_permissionHubEnabled_shouldReturnTrue() { + DeviceConfig.setProperty(DeviceConfig.NAMESPACE_PRIVACY, + Utils.PROPERTY_PERMISSIONS_HUB_ENABLED, "true", true); + assertThat(mController.isAvailable()).isEqualTo(true); } @@ -111,6 +118,39 @@ public class RecentLocationAccessPreferenceControllerTest { assertThat(details.hasOnClickListeners()).isTrue(); } + @Test + public void updateState_whenAppListMoreThanThree_shouldDisplayTopThreeApps() { + final List accesses = createMockAccesses(6); + doReturn(accesses).when(mRecentLocationApps).getAppListSorted(); + mController.displayPreference(mScreen); + mController.updateState(mLayoutPreference); + + // The widget can display the top 3 apps from the list when there're more than 3. + final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view); + final ImageView appIconView1 = app1View.findViewById(R.id.app_icon); + final TextView appTitle1 = app1View.findViewById(R.id.app_title); + + assertThat(app1View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView1.getDrawable()).isNotNull(); + assertThat(appTitle1.getText()).isEqualTo("appTitle0"); + + final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view); + final ImageView appIconView2 = app2View.findViewById(R.id.app_icon); + final TextView appTitle2 = app2View.findViewById(R.id.app_title); + + assertThat(app2View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView2.getDrawable()).isNotNull(); + assertThat(appTitle2.getText()).isEqualTo("appTitle1"); + + final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view); + final ImageView appIconView3 = app3View.findViewById(R.id.app_icon); + final TextView appTitle3 = app3View.findViewById(R.id.app_title); + + assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(appIconView3.getDrawable()).isNotNull(); + assertThat(appTitle3.getText()).isEqualTo("appTitle2"); + } + private List createMockAccesses(int count) { final List accesses = new ArrayList<>(); for (int i = 0; i < count; i++) { From 2a829315a02277318d9d900122c2d3d6c683a753 Mon Sep 17 00:00:00 2001 From: Edgar Wang Date: Wed, 14 Apr 2021 09:54:04 +0800 Subject: [PATCH 03/17] Apply SettingsPreferenceTheme in Settings - Set all of preference style inherit from SettingsPreferenceTheme - Apply to Theme.Settings and Theme.Settings.Home - Fix robotest failed in ScreenTimeoutSettingsTest Bug: 185206291 Test: manual & robotest Change-Id: I855d003b10348569903855fcbf235bc00265658b (cherry picked from commit 817a167416eecfa6f6455e94f31ffc9ff59ea0a4) --- res/values/styles_preference.xml | 4 ++-- res/values/themes.xml | 3 ++- res/values/themes_suw.xml | 2 +- tests/robotests/res/values/themes.xml | 2 +- .../android/settings/display/ScreenTimeoutSettingsTest.java | 5 +++++ .../src/com/android/settings/widget/CardPreferenceTest.java | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml index 6453458e9b4..c162fc46b5b 100644 --- a/res/values/styles_preference.xml +++ b/res/values/styles_preference.xml @@ -19,7 +19,7 @@ - - diff --git a/res/values/themes.xml b/res/values/themes.xml index 4df4a78f31e..444ec72e9f1 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -26,6 +26,7 @@ diff --git a/tests/robotests/res/values/themes.xml b/tests/robotests/res/values/themes.xml index 92edb17b503..0fe63284510 100644 --- a/tests/robotests/res/values/themes.xml +++ b/tests/robotests/res/values/themes.xml @@ -13,7 +13,7 @@ #ffffff #ffffff #ffffff - @style/PreferenceTheme + @style/SettingsPreferenceTheme true @android:color/white diff --git a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java index 771a86359ff..c4f55808870 100644 --- a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java +++ b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java @@ -73,6 +73,9 @@ public class ScreenTimeoutSettingsTest { @Mock AdaptiveSleepPreferenceController mAdaptiveSleepPreferenceController; + @Mock + AdaptiveSleepCameraStatePreferenceController mAdaptiveSleepCameraStatePreferenceController; + @Mock Preference mDisableOptionsPreference; @@ -98,6 +101,8 @@ public class ScreenTimeoutSettingsTest { mSettings.mAdaptiveSleepController = mAdaptiveSleepPreferenceController; mSettings.mAdaptiveSleepPermissionController = mPermissionPreferenceController; + mSettings.mAdaptiveSleepCameraStatePreferenceController = + mAdaptiveSleepCameraStatePreferenceController; } @Test diff --git a/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java index 730489795fe..6d4a6bbd4d8 100644 --- a/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java @@ -37,7 +37,7 @@ public class CardPreferenceTest { @Before public void setUp() { mContext = RuntimeEnvironment.application; - mContext.setTheme(R.style.PreferenceTheme); + mContext.setTheme(R.style.SettingsPreferenceTheme); mCardPreference = new CardPreference(mContext); } From 83293405aa300005aaf988afdfad21058ac336d5 Mon Sep 17 00:00:00 2001 From: Edgar Wang Date: Wed, 14 Apr 2021 09:54:04 +0800 Subject: [PATCH 04/17] Apply SettingsPreferenceTheme in Settings - Set all of preference style inherit from SettingsPreferenceTheme - Apply to Theme.Settings and Theme.Settings.Home - Fix robotest failed in ScreenTimeoutSettingsTest Bug: 185206291 Test: manual & robotest Change-Id: I855d003b10348569903855fcbf235bc00265658b (cherry picked from commit 817a167416eecfa6f6455e94f31ffc9ff59ea0a4) --- res/values/styles_preference.xml | 4 ++-- res/values/themes.xml | 3 ++- res/values/themes_suw.xml | 2 +- tests/robotests/res/values/themes.xml | 2 +- .../android/settings/display/ScreenTimeoutSettingsTest.java | 5 +++++ .../src/com/android/settings/widget/CardPreferenceTest.java | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/res/values/styles_preference.xml b/res/values/styles_preference.xml index 6453458e9b4..c162fc46b5b 100644 --- a/res/values/styles_preference.xml +++ b/res/values/styles_preference.xml @@ -19,7 +19,7 @@ - - diff --git a/res/values/themes.xml b/res/values/themes.xml index 4df4a78f31e..444ec72e9f1 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -26,6 +26,7 @@ diff --git a/tests/robotests/res/values/themes.xml b/tests/robotests/res/values/themes.xml index 92edb17b503..0fe63284510 100644 --- a/tests/robotests/res/values/themes.xml +++ b/tests/robotests/res/values/themes.xml @@ -13,7 +13,7 @@ #ffffff #ffffff #ffffff - @style/PreferenceTheme + @style/SettingsPreferenceTheme true @android:color/white diff --git a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java index 771a86359ff..c4f55808870 100644 --- a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java +++ b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java @@ -73,6 +73,9 @@ public class ScreenTimeoutSettingsTest { @Mock AdaptiveSleepPreferenceController mAdaptiveSleepPreferenceController; + @Mock + AdaptiveSleepCameraStatePreferenceController mAdaptiveSleepCameraStatePreferenceController; + @Mock Preference mDisableOptionsPreference; @@ -98,6 +101,8 @@ public class ScreenTimeoutSettingsTest { mSettings.mAdaptiveSleepController = mAdaptiveSleepPreferenceController; mSettings.mAdaptiveSleepPermissionController = mPermissionPreferenceController; + mSettings.mAdaptiveSleepCameraStatePreferenceController = + mAdaptiveSleepCameraStatePreferenceController; } @Test diff --git a/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java index 730489795fe..6d4a6bbd4d8 100644 --- a/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java +++ b/tests/robotests/src/com/android/settings/widget/CardPreferenceTest.java @@ -37,7 +37,7 @@ public class CardPreferenceTest { @Before public void setUp() { mContext = RuntimeEnvironment.application; - mContext.setTheme(R.style.PreferenceTheme); + mContext.setTheme(R.style.SettingsPreferenceTheme); mCardPreference = new CardPreference(mContext); } From 1466862168889ea78238cad2d48d6161b6fd5225 Mon Sep 17 00:00:00 2001 From: bsears Date: Mon, 3 May 2021 17:59:11 +0000 Subject: [PATCH 05/17] Revert "Fixes 'no ripple effect' issue for screen attention setting" This reverts commit 20d1da2b6298ade2a2390a66f98a1d12381e5e8f. Reason for revert: Based on bisection, this is the likely root cause of b/186904496 Bug: 186904496 Change-Id: I0eaa026b52610d7ef4543c32791531971e68f8e6 (cherry picked from commit 30e9ba1e52f072dd73e18cbee10bb6e3adc5b1e0) --- ...veSleepPermissionPreferenceController.java | 29 ++++++-------- .../AdaptiveSleepPreferenceController.java | 39 ++++++++----------- .../display/ScreenTimeoutSettings.java | 18 +++------ ...AdaptiveSleepPreferenceControllerTest.java | 1 - .../display/ScreenTimeoutSettingsTest.java | 4 +- 5 files changed, 36 insertions(+), 55 deletions(-) diff --git a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java index 8e4db0d26ad..0d21e9caf80 100644 --- a/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java +++ b/src/com/android/settings/display/AdaptiveSleepPermissionPreferenceController.java @@ -37,18 +37,26 @@ public class AdaptiveSleepPermissionPreferenceController { @VisibleForTesting BannerMessagePreference mPreference; private final PackageManager mPackageManager; - private final Context mContext; public AdaptiveSleepPermissionPreferenceController(Context context) { + final String packageName = context.getPackageManager().getAttentionServicePackageName(); mPackageManager = context.getPackageManager(); - mContext = context; + final Intent intent = new Intent( + android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); + intent.setData(Uri.parse("package:" + packageName)); + mPreference = new BannerMessagePreference(context); + mPreference.setTitle(R.string.adaptive_sleep_title_no_permission); + mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission); + mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button); + mPreference.setPositiveButtonOnClickListener(p -> { + context.startActivity(intent); + }); } /** * Adds the controlled preference to the provided preference screen. */ public void addToScreen(PreferenceScreen screen) { - initializePreference(); if (!hasSufficientPermission(mPackageManager)) { screen.addPreference(mPreference); } @@ -60,19 +68,4 @@ public class AdaptiveSleepPermissionPreferenceController { public void updateVisibility() { mPreference.setVisible(!hasSufficientPermission(mPackageManager)); } - - private void initializePreference() { - final String packageName = mContext.getPackageManager().getAttentionServicePackageName(); - final Intent intent = new Intent( - android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS); - intent.setData(Uri.parse("package:" + packageName)); - mPreference = new BannerMessagePreference(mContext); - mPreference.setTitle(R.string.adaptive_sleep_title_no_permission); - mPreference.setSummary(R.string.adaptive_sleep_summary_no_permission); - mPreference.setPositiveButtonText(R.string.adaptive_sleep_manage_permission_button); - mPreference.setPositiveButtonOnClickListener(p -> { - mContext.startActivity(intent); - }); - } - } diff --git a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java index aa02ce51c81..70d8a79f390 100644 --- a/src/com/android/settings/display/AdaptiveSleepPreferenceController.java +++ b/src/com/android/settings/display/AdaptiveSleepPreferenceController.java @@ -49,10 +49,10 @@ public class AdaptiveSleepPreferenceController { public static final String PREFERENCE_KEY = "adaptive_sleep"; private static final int DEFAULT_VALUE = 0; private final SensorPrivacyManager mPrivacyManager; - private final RestrictionUtils mRestrictionUtils; - private final PackageManager mPackageManager; - private final Context mContext; - private final MetricsFeatureProvider mMetricsFeatureProvider; + private RestrictionUtils mRestrictionUtils; + private PackageManager mPackageManager; + private Context mContext; + private MetricsFeatureProvider mMetricsFeatureProvider; @VisibleForTesting RestrictedSwitchPreference mPreference; @@ -62,6 +62,19 @@ public class AdaptiveSleepPreferenceController { mRestrictionUtils = restrictionUtils; mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider(); mPrivacyManager = SensorPrivacyManager.getInstance(context); + mPreference = new RestrictedSwitchPreference(context); + mPreference.setTitle(R.string.adaptive_sleep_title); + mPreference.setSummary(R.string.adaptive_sleep_description); + mPreference.setChecked(isChecked()); + mPreference.setKey(PREFERENCE_KEY); + mPreference.setOnPreferenceClickListener(preference -> { + final boolean isChecked = ((RestrictedSwitchPreference) preference).isChecked(); + mMetricsFeatureProvider.action(context, SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED, + isChecked); + Settings.Secure.putInt(context.getContentResolver(), + Settings.Secure.ADAPTIVE_SLEEP, isChecked ? 1 : DEFAULT_VALUE); + return true; + }); mPackageManager = context.getPackageManager(); } @@ -73,7 +86,6 @@ public class AdaptiveSleepPreferenceController { * Adds the controlled preference to the provided preference screen. */ public void addToScreen(PreferenceScreen screen) { - initializePreference(); updatePreference(); screen.addPreference(mPreference); } @@ -91,23 +103,6 @@ public class AdaptiveSleepPreferenceController { } } - @VisibleForTesting - void initializePreference() { - mPreference = new RestrictedSwitchPreference(mContext); - mPreference.setTitle(R.string.adaptive_sleep_title); - mPreference.setSummary(R.string.adaptive_sleep_description); - mPreference.setChecked(isChecked()); - mPreference.setKey(PREFERENCE_KEY); - mPreference.setOnPreferenceChangeListener((preference, value) -> { - final boolean isChecked = (Boolean) value; - mMetricsFeatureProvider.action(mContext, SettingsEnums.ACTION_SCREEN_ATTENTION_CHANGED, - isChecked); - Settings.Secure.putInt(mContext.getContentResolver(), - Settings.Secure.ADAPTIVE_SLEEP, isChecked ? 1 : DEFAULT_VALUE); - return true; - }); - } - @VisibleForTesting boolean isChecked() { return hasSufficientPermission(mContext.getPackageManager()) && !isCameraLocked() diff --git a/src/com/android/settings/display/ScreenTimeoutSettings.java b/src/com/android/settings/display/ScreenTimeoutSettings.java index 6dfb22529fe..27e1e1bfc45 100644 --- a/src/com/android/settings/display/ScreenTimeoutSettings.java +++ b/src/com/android/settings/display/ScreenTimeoutSettings.java @@ -71,15 +71,11 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements private CharSequence[] mInitialEntries; private CharSequence[] mInitialValues; private FooterPreference mPrivacyPreference; - private final MetricsFeatureProvider mMetricsFeatureProvider; + private MetricsFeatureProvider mMetricsFeatureProvider; private SensorPrivacyManager mPrivacyManager; - @VisibleForTesting - Context mContext; - @VisibleForTesting RestrictedLockUtils.EnforcedAdmin mAdmin; - @VisibleForTesting Preference mDisableOptionsPreference; @@ -101,7 +97,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements @Override public void onAttach(Context context) { super.onAttach(context); - mContext = context; mInitialEntries = getResources().getStringArray(R.array.screen_timeout_entries); mInitialValues = getResources().getStringArray(R.array.screen_timeout_values); mAdaptiveSleepController = new AdaptiveSleepPreferenceController(context); @@ -109,6 +104,11 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements context); mAdaptiveSleepCameraStatePreferenceController = new AdaptiveSleepCameraStatePreferenceController(context); + mPrivacyPreference = new FooterPreference(context); + mPrivacyPreference.setIcon(R.drawable.ic_privacy_shield_24dp); + mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy); + mPrivacyPreference.setSelectable(false); + mPrivacyPreference.setLayoutResource(R.layout.preference_footer); mPrivacyManager = SensorPrivacyManager.getInstance(context); mPrivacyManager.addSensorPrivacyListener(CAMERA, (sensor, enabled) -> mAdaptiveSleepController.updatePreference()); @@ -167,12 +167,6 @@ public class ScreenTimeoutSettings extends RadioButtonPickerFragment implements preferenceWithLargestTimeout.setChecked(true); } - mPrivacyPreference = new FooterPreference(mContext); - mPrivacyPreference.setIcon(R.drawable.ic_privacy_shield_24dp); - mPrivacyPreference.setTitle(R.string.adaptive_sleep_privacy); - mPrivacyPreference.setSelectable(false); - mPrivacyPreference.setLayoutResource(R.layout.preference_footer); - if (isScreenAttentionAvailable(getContext())) { mAdaptiveSleepPermissionController.addToScreen(screen); mAdaptiveSleepCameraStatePreferenceController.addToScreen(screen); diff --git a/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java index 880f9ccdcaf..843870d0a9e 100644 --- a/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/AdaptiveSleepPreferenceControllerTest.java @@ -84,7 +84,6 @@ public class AdaptiveSleepPreferenceControllerTest { eq(UserManager.DISALLOW_CONFIG_SCREEN_TIMEOUT))).thenReturn(null); mController = new AdaptiveSleepPreferenceController(mContext, mRestrictionUtils); - mController.initializePreference(); when(mController.isCameraLocked()).thenReturn(false); } diff --git a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java index 24bcde871e4..c4f55808870 100644 --- a/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java +++ b/tests/robotests/src/com/android/settings/display/ScreenTimeoutSettingsTest.java @@ -60,6 +60,8 @@ public class ScreenTimeoutSettingsTest { private ScreenTimeoutSettings mSettings; private Context mContext; private ContentResolver mContentResolver; + + @Mock private Resources mResources; @Mock @@ -83,9 +85,7 @@ public class ScreenTimeoutSettingsTest { FakeFeatureFactory.setupForTest(); mContext = spy(getApplicationContext()); mSettings = spy(new ScreenTimeoutSettings()); - mSettings.mContext = mContext; mContentResolver = mContext.getContentResolver(); - mResources = spy(mContext.getResources()); doReturn(TIMEOUT_ENTRIES).when(mResources).getStringArray(R.array.screen_timeout_entries); doReturn(TIMEOUT_VALUES).when(mResources).getStringArray(R.array.screen_timeout_entries); From 199bc02ab0d4d6cbbd87c0123dff38463a83cca6 Mon Sep 17 00:00:00 2001 From: Curtis Belmonte Date: Wed, 26 May 2021 15:45:38 -0700 Subject: [PATCH 06/17] Fix crash due to traffic light face Lottie animation Load the animation asset only if enabled in the resource config, to avoid crashing on unsupported device configurations. Test: Manual Fixes: 189290180 Change-Id: Iae46c735277777705c1d6f4595b557e4b0b1aef7 (cherry picked from commit adf0cabe0a1ac3efecb2f46dffd0ca5fa22ba5fb) --- res/layout/face_enroll_education.xml | 4 ++-- .../android/settings/biometrics/face/FaceEnrollEducation.java | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/res/layout/face_enroll_education.xml b/res/layout/face_enroll_education.xml index 646856fcfdd..01494790c97 100644 --- a/res/layout/face_enroll_education.xml +++ b/res/layout/face_enroll_education.xml @@ -47,6 +47,7 @@ android:layout_height="wrap_content" app:sudVideo="@raw/face_education"/> + + app:lottie_loop="true" /> Date: Wed, 16 Jun 2021 17:26:12 +0800 Subject: [PATCH 07/17] Fix the issue of permanent loading when Wi-Fi is disabled Bug: 173207801 Test: manual test make RunSettingsRoboTests ROBOTEST_FILTER=NetworkProviderSettingsTest Change-Id: Ib46c620f10987ba52787aae8b5beddb5c68e0e17 (cherry picked from commit 58ff170086ef1205bebc76871c1cf5e3994ced51) --- .../network/NetworkProviderSettings.java | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java index 9942ca3c60f..b34d9cd7a63 100644 --- a/src/com/android/settings/network/NetworkProviderSettings.java +++ b/src/com/android/settings/network/NetworkProviderSettings.java @@ -169,14 +169,18 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment return WifiPickerTracker.isVerboseLoggingEnabled(); } - private boolean mIsWifiEntriesLoading; + private boolean mIsViewLoading; + private final Runnable mRemoveLoadingRunnable = () -> { + if (mIsViewLoading) { + setLoading(false, false); + mIsViewLoading = false; + } + }; + private boolean mIsWifiEntryListStale = true; private final Runnable mUpdateWifiEntryPreferencesRunnable = () -> { updateWifiEntryPreferences(); - if (mIsWifiEntriesLoading) { - setLoading(false, false); - mIsWifiEntriesLoading = false; - } + getView().postDelayed(mRemoveLoadingRunnable, 10); }; private final Runnable mHideProgressBarRunnable = () -> { setProgressBarVisible(false); @@ -250,14 +254,23 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); - final Activity activity = getActivity(); - if (activity != null) { - mProgressHeader = setPinnedHeaderView(R.layout.progress_header) - .findViewById(R.id.progress_bar_animation); - setProgressBarVisible(false); + Activity activity = getActivity(); + if (activity == null) { + return; + } + + mProgressHeader = setPinnedHeaderView(R.layout.progress_header) + .findViewById(R.id.progress_bar_animation); + setProgressBarVisible(false); + + mWifiManager = activity.getSystemService(WifiManager.class); + if (mWifiManager != null) { + setLoading(true, false); + mIsViewLoading = true; + if (!mWifiManager.isWifiEnabled()) { + getView().postDelayed(mRemoveLoadingRunnable, 100); + } } - setLoading(true, false); - mIsWifiEntriesLoading = true; } @Override @@ -339,12 +352,6 @@ public class NetworkProviderSettings extends RestrictedSettingsFragment mWifiPickerTracker = mWifiPickerTrackerHelper.getWifiPickerTracker(); mInternetUpdater = new InternetUpdater(getContext(), getSettingsLifecycle(), this); - final Activity activity = getActivity(); - - if (activity != null) { - mWifiManager = getActivity().getSystemService(WifiManager.class); - } - mConnectListener = new WifiConnectListener(getActivity()); mSaveListener = new WifiManager.ActionListener() { From ea9c82d2d0530be75ff2563941c1bd9ae2a5ef75 Mon Sep 17 00:00:00 2001 From: bsears Date: Wed, 30 Jun 2021 14:53:13 +0000 Subject: [PATCH 08/17] Revert "Return enrollment consent status to caller." This reverts commit eb1dac69f091e728171f5b8b91a6c31881edbef9. Reason for revert: Based on bisection, this CL is the root cause for bug 192420564, which breaks Setup Wizard. Bug: 192420564 Change-Id: I8d9aee7fe2415e134fcc981b0548bd9ce300db55 (cherry picked from commit c358adad5680d3a8416969e7c739195d995ee5da) --- .../biometrics/BiometricEnrollActivity.java | 128 ++++++++---------- .../MultiBiometricEnrollHelper.java | 8 ++ .../biometrics/ParentalConsentHelper.java | 2 - 3 files changed, 63 insertions(+), 75 deletions(-) diff --git a/src/com/android/settings/biometrics/BiometricEnrollActivity.java b/src/com/android/settings/biometrics/BiometricEnrollActivity.java index 3b8f25507e9..db5e003456a 100644 --- a/src/com/android/settings/biometrics/BiometricEnrollActivity.java +++ b/src/com/android/settings/biometrics/BiometricEnrollActivity.java @@ -71,7 +71,6 @@ public class BiometricEnrollActivity extends InstrumentedActivity { private static final int REQUEST_CHOOSE_OPTIONS = 3; // prompt hand phone back to parent after enrollment private static final int REQUEST_HANDOFF_PARENT = 4; - private static final int REQUEST_SINGLE_ENROLL = 5; public static final int RESULT_SKIP = BiometricEnrollBase.RESULT_SKIP; @@ -79,13 +78,8 @@ public class BiometricEnrollActivity extends InstrumentedActivity { // this only applies to fingerprint. public static final String EXTRA_SKIP_INTRO = "skip_intro"; - // Intent extra. If true, parental consent will be requested before user enrollment. - public static final String EXTRA_REQUIRE_PARENTAL_CONSENT = "require_consent"; - - // If EXTRA_REQUIRE_PARENTAL_CONSENT was used to start the activity then the result - // intent will include this extra containing a bundle of the form: - // "modality" -> consented (boolean). - public static final String EXTRA_PARENTAL_CONSENT_STATUS = "consent_status"; + // TODO: temporary while waiting for team to add real flag + public static final String EXTRA_TEMP_REQUIRE_PARENTAL_CONSENT = "require_consent"; private static final String SAVED_STATE_CONFIRMING_CREDENTIALS = "confirming_credentials"; private static final String SAVED_STATE_ENROLL_ACTION_LOGGED = "enroll_action_logged"; @@ -195,7 +189,7 @@ public class BiometricEnrollActivity extends InstrumentedActivity { // TODO(b/188847063): replace with real flag when ready mParentalOptionsRequired = intent.getBooleanExtra( - BiometricEnrollActivity.EXTRA_REQUIRE_PARENTAL_CONSENT, false); + BiometricEnrollActivity.EXTRA_TEMP_REQUIRE_PARENTAL_CONSENT, false); if (mParentalOptionsRequired && mParentalOptions == null) { mParentalConsentHelper = new ParentalConsentHelper( @@ -207,6 +201,19 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } private void startEnroll() { + // TODO(b/188847063): This can be deleted, but log it now until it's wired up for real. + if (mParentalOptionsRequired) { + if (mParentalOptions == null) { + throw new IllegalStateException("consent options required, but not set"); + } + Log.d(TAG, "consent for face: " + + ParentalConsentHelper.hasFaceConsent(mParentalOptions)); + Log.d(TAG, "consent for fingerprint: " + + ParentalConsentHelper.hasFingerprintConsent(mParentalOptions)); + } else { + Log.d(TAG, "startEnroll without requiring consent"); + } + // Default behavior is to enroll BIOMETRIC_WEAK or above. See ACTION_BIOMETRIC_ENROLL. final int authenticators = getIntent().getIntExtra( EXTRA_BIOMETRIC_AUTHENTICATORS_ALLOWED, Authenticators.BIOMETRIC_WEAK); @@ -227,38 +234,21 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } } - boolean canUseFace = mHasFeatureFace; - boolean canUseFingerprint = mHasFeatureFingerprint; - if (mParentalOptionsRequired) { - if (mParentalOptions == null) { - throw new IllegalStateException("consent options required, but not set"); - } - canUseFace = canUseFace - && ParentalConsentHelper.hasFaceConsent(mParentalOptions); - canUseFingerprint = canUseFingerprint - && ParentalConsentHelper.hasFingerprintConsent(mParentalOptions); - } - // This will need to be updated if the device has sensors other than BIOMETRIC_STRONG if (!setupWizard && authenticators == BiometricManager.Authenticators.DEVICE_CREDENTIAL) { launchCredentialOnlyEnroll(); - } else if (canUseFace && canUseFingerprint) { + } else if (mHasFeatureFace && mHasFeatureFingerprint) { if (mParentalOptionsRequired && mGkPwHandle != null) { launchFaceAndFingerprintEnroll(); } else { setOrConfirmCredentialsNow(); } - } else if (canUseFingerprint) { + } else if (mHasFeatureFingerprint) { launchFingerprintOnlyEnroll(); - } else if (canUseFace) { + } else if (mHasFeatureFace) { launchFaceOnlyEnroll(); - } else { // no modalities available - if (mParentalOptionsRequired) { - Log.d(TAG, "No consent for any modality: skipping enrollment"); - setResult(RESULT_OK, newResultIntent()); - } else { - Log.e(TAG, "Unknown state, finishing (was SUW: " + setupWizard + ")"); - } + } else { + Log.e(TAG, "Unknown state, finishing (was SUW: " + setupWizard + ")"); finish(); } } @@ -285,7 +275,7 @@ public class BiometricEnrollActivity extends InstrumentedActivity { if (mParentalConsentHelper != null) { handleOnActivityResultWhileConsenting(requestCode, resultCode, data); } else { - handleOnActivityResultWhileEnrolling(requestCode, resultCode, data); + handleOnActivityResultWhileEnrollingMultiple(requestCode, resultCode, data); } } @@ -315,10 +305,8 @@ public class BiometricEnrollActivity extends InstrumentedActivity { final boolean isStillPrompting = mParentalConsentHelper.launchNext( this, REQUEST_CHOOSE_OPTIONS, resultCode, data); if (!isStillPrompting) { - Log.d(TAG, "Enrollment consent options set, starting enrollment"); - mParentalOptions = mParentalConsentHelper.getConsentResult(); - mParentalConsentHelper = null; - startEnroll(); + Log.d(TAG, "Enrollment options set, requesting handoff"); + launchHandoffToParent(); } } else { Log.d(TAG, "Unknown or cancelled parental consent"); @@ -326,6 +314,18 @@ public class BiometricEnrollActivity extends InstrumentedActivity { finish(); } break; + case REQUEST_HANDOFF_PARENT: + if (resultCode == RESULT_OK) { + Log.d(TAG, "Enrollment options set, starting enrollment"); + mParentalOptions = mParentalConsentHelper.getConsentResult(); + mParentalConsentHelper = null; + startEnroll(); + } else { + Log.d(TAG, "Unknown or cancelled handoff"); + setResult(RESULT_CANCELED); + finish(); + } + break; default: Log.w(TAG, "Unknown consenting requestCode: " + requestCode + ", finishing"); finish(); @@ -333,13 +333,9 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } // handles responses while multi biometric enrollment is pending - private void handleOnActivityResultWhileEnrolling( + private void handleOnActivityResultWhileEnrollingMultiple( int requestCode, int resultCode, Intent data) { - if (requestCode == REQUEST_HANDOFF_PARENT) { - Log.d(TAG, "Enrollment complete, requesting handoff, result: " + resultCode); - setResult(RESULT_OK, newResultIntent()); - finish(); - } else if (mMultiBiometricEnrollHelper == null) { + if (mMultiBiometricEnrollHelper == null) { overridePendingTransition(R.anim.sud_slide_next_in, R.anim.sud_slide_next_out); switch (requestCode) { @@ -359,37 +355,15 @@ public class BiometricEnrollActivity extends InstrumentedActivity { finish(); } break; - case REQUEST_SINGLE_ENROLL: - finishOrLaunchHandToParent(resultCode); - break; default: Log.w(TAG, "Unknown enrolling requestCode: " + requestCode + ", finishing"); finish(); } } else { - Log.d(TAG, "RequestCode: " + requestCode + " resultCode: " + resultCode); - BiometricUtils.removeGatekeeperPasswordHandle(this, mGkPwHandle); - finishOrLaunchHandToParent(resultCode); + mMultiBiometricEnrollHelper.onActivityResult(requestCode, resultCode, data); } } - private void finishOrLaunchHandToParent(int resultCode) { - if (mParentalOptionsRequired) { - launchHandoffToParent(); - } else { - setResult(resultCode); - finish(); - } - } - - private Intent newResultIntent() { - final Intent intent = new Intent(); - final Bundle consentStatus = mParentalOptions.deepCopy(); - intent.putExtra(EXTRA_PARENTAL_CONSENT_STATUS, consentStatus); - Log.v(TAG, "Result consent status: " + consentStatus); - return intent; - } - private static boolean isSuccessfulConfirmOrChooseCredential(int requestCode, int resultCode) { final boolean okChoose = requestCode == REQUEST_CHOOSE_LOCK && resultCode == ChooseLockPattern.RESULT_FINISHED; @@ -410,8 +384,8 @@ public class BiometricEnrollActivity extends InstrumentedActivity { super.onStop(); if (mConfirmingCredentials - || mParentalOptionsRequired - || mMultiBiometricEnrollHelper != null) { + || mMultiBiometricEnrollHelper != null + || mParentalConsentHelper != null) { return; } @@ -421,6 +395,7 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } } + private void setOrConfirmCredentialsNow() { if (!mConfirmingCredentials) { mConfirmingCredentials = true; @@ -479,14 +454,21 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } } - // This should only be used to launch enrollment for single-sensor devices. - private void launchSingleSensorEnrollActivity(@NonNull Intent intent, int requestCode) { + /** + * This should only be used to launch enrollment for single-sensor devices, which use + * FLAG_ACTIVITY_FORWARD_RESULT path. + * + * @param intent Enrollment activity that should be started (e.g. FaceEnrollIntroduction.class, + * etc). + */ + private void launchSingleSensorEnrollActivity(@NonNull Intent intent) { + intent.setFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT); byte[] hardwareAuthToken = null; if (this instanceof InternalActivity) { hardwareAuthToken = getIntent().getByteArrayExtra( ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN); } - BiometricUtils.launchEnrollForResult(this, intent, requestCode, hardwareAuthToken, + BiometricUtils.launchEnrollForResult(this, intent, 0 /* requestCode */, hardwareAuthToken, mGkPwHandle, mUserId); } @@ -495,7 +477,7 @@ public class BiometricEnrollActivity extends InstrumentedActivity { // If only device credential was specified, ask the user to only set that up. intent = new Intent(this, ChooseLockGeneric.class); intent.putExtra(ChooseLockGeneric.ChooseLockGenericFragment.HIDE_INSECURE_OPTIONS, true); - launchSingleSensorEnrollActivity(intent, 0 /* requestCode */); + launchSingleSensorEnrollActivity(intent); } private void launchFingerprintOnlyEnroll() { @@ -507,12 +489,12 @@ public class BiometricEnrollActivity extends InstrumentedActivity { } else { intent = BiometricUtils.getFingerprintIntroIntent(this, getIntent()); } - launchSingleSensorEnrollActivity(intent, REQUEST_SINGLE_ENROLL); + launchSingleSensorEnrollActivity(intent); } private void launchFaceOnlyEnroll() { final Intent intent = BiometricUtils.getFaceIntroIntent(this, getIntent()); - launchSingleSensorEnrollActivity(intent, REQUEST_SINGLE_ENROLL); + launchSingleSensorEnrollActivity(intent); } private void launchFaceAndFingerprintEnroll() { diff --git a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java index 44d75c5808d..74d7c535e05 100644 --- a/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java +++ b/src/com/android/settings/biometrics/MultiBiometricEnrollHelper.java @@ -20,6 +20,7 @@ import android.app.PendingIntent; import android.content.Intent; import android.hardware.face.FaceManager; import android.hardware.fingerprint.FingerprintManager; +import android.util.Log; import androidx.annotation.NonNull; import androidx.fragment.app.FragmentActivity; @@ -106,4 +107,11 @@ public class MultiBiometricEnrollHelper { hardwareAuthToken, mGkPwHandle, mUserId); })); } + + void onActivityResult(int requestCode, int resultCode, Intent data) { + Log.d(TAG, "RequestCode: " + requestCode + " resultCode: " + resultCode); + BiometricUtils.removeGatekeeperPasswordHandle(mActivity, mGkPwHandle); + mActivity.setResult(resultCode); + mActivity.finish(); + } } diff --git a/src/com/android/settings/biometrics/ParentalConsentHelper.java b/src/com/android/settings/biometrics/ParentalConsentHelper.java index 6c4004e5c55..905a95527ef 100644 --- a/src/com/android/settings/biometrics/ParentalConsentHelper.java +++ b/src/com/android/settings/biometrics/ParentalConsentHelper.java @@ -46,7 +46,6 @@ public class ParentalConsentHelper { private static final String KEY_FACE_CONSENT = "face"; private static final String KEY_FINGERPRINT_CONSENT = "fingerprint"; - private static final String KEY_IRIS_CONSENT = "iris"; private final boolean mRequireFace; private final boolean mRequireFingerprint; @@ -154,7 +153,6 @@ public class ParentalConsentHelper { result.putBoolean(KEY_FACE_CONSENT, mConsentFace != null ? mConsentFace : false); result.putBoolean(KEY_FINGERPRINT_CONSENT, mConsentFingerprint != null ? mConsentFingerprint : false); - result.putBoolean(KEY_IRIS_CONSENT, false); return result; } From ebce137f63dfb46ad8a0bfdd3c6ad196a2518b4f Mon Sep 17 00:00:00 2001 From: Daniel Chapin Date: Mon, 12 Jul 2021 22:54:21 +0000 Subject: [PATCH 09/17] Revert "Rename Enhanced MAC Randomization to Non-Persistent" Revert submission 15050857-RenameEnhancedMac Reason for revert: Droidfood blocking Bug: 193375403 Reverted Changes: I5d647a666:Rename Enhanced MAC Randomization to Non-Persisten... I48a326f98:Update old terminology for Non-persistent Mac Rand... Change-Id: Ic6ff02dad064f8d8c7dbaab51c658da12a4d8555 (cherry picked from commit e7cb2762f908d8cfc96b39c46fcf4e03efc07e5b) --- .../DevelopmentSettingsDashboardFragment.java | 2 +- ...MacRandomizationPreferenceController.java} | 22 ++++++++--------- ...andomizationPreferenceControllerTest.java} | 24 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) rename src/com/android/settings/development/{WifiNonPersistentMacRandomizationPreferenceController.java => WifiEnhancedMacRandomizationPreferenceController.java} (71%) rename tests/robotests/src/com/android/settings/development/{WifiNonPersistentMacRandomizationPreferenceControllerTest.java => WifiEnhancedMacRandomizationPreferenceControllerTest.java} (76%) diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index c02ae42b376..94b67aa76bb 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -505,7 +505,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new WifiDisplayCertificationPreferenceController(context)); controllers.add(new WifiVerboseLoggingPreferenceController(context)); controllers.add(new WifiScanThrottlingPreferenceController(context)); - controllers.add(new WifiNonPersistentMacRandomizationPreferenceController(context)); + controllers.add(new WifiEnhancedMacRandomizationPreferenceController(context)); controllers.add(new MobileDataAlwaysOnPreferenceController(context)); controllers.add(new TetheringHardwareAccelPreferenceController(context)); controllers.add(new BluetoothDeviceNoNamePreferenceController(context)); diff --git a/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java b/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java similarity index 71% rename from src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java rename to src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java index 3f6d775c0b7..af44f5b2020 100644 --- a/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java +++ b/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java @@ -26,30 +26,30 @@ import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** - * Developer option controller for non-persistent MAC randomization. + * Developer option controller for enhanced MAC randomization. */ -public class WifiNonPersistentMacRandomizationPreferenceController +public class WifiEnhancedMacRandomizationPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { - private static final String WIFI_NON_PERSISTENT_MAC_RANDOMIZATION_KEY = - "wifi_non_persistent_mac_randomization"; - private static final String NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG = - "non_persistent_mac_randomization_force_enabled"; + private static final String WIFI_ENHANCED_MAC_RANDOMIZATION_KEY = + "wifi_enhanced_mac_randomization"; + private static final String ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG = + "enhanced_mac_randomization_force_enabled"; - public WifiNonPersistentMacRandomizationPreferenceController(Context context) { + public WifiEnhancedMacRandomizationPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { - return WIFI_NON_PERSISTENT_MAC_RANDOMIZATION_KEY; + return WIFI_ENHANCED_MAC_RANDOMIZATION_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int isEnabledInt = ((Boolean) newValue) ? 1 : 0; Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, isEnabledInt); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, isEnabledInt); return true; } @@ -57,7 +57,7 @@ public class WifiNonPersistentMacRandomizationPreferenceController public void updateState(Preference preference) { boolean enabled = false; if (Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0) == 1) { + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0) == 1) { enabled = true; } ((SwitchPreference) mPreference).setChecked(enabled); @@ -67,7 +67,7 @@ public class WifiNonPersistentMacRandomizationPreferenceController protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0); ((SwitchPreference) mPreference).setChecked(false); } } diff --git a/tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java similarity index 76% rename from tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java index b654387f9ef..25e5a2274f1 100644 --- a/tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java @@ -36,48 +36,48 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) -public class WifiNonPersistentMacRandomizationPreferenceControllerTest { - private static final String NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG = - "non_persistent_mac_randomization_force_enabled"; +public class WifiEnhancedMacRandomizationPreferenceControllerTest { + private static final String ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG = + "enhanced_mac_randomization_force_enabled"; @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; private Context mContext; - private WifiNonPersistentMacRandomizationPreferenceController mController; + private WifiEnhancedMacRandomizationPreferenceController mController; @Before public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; - mController = new WifiNonPersistentMacRandomizationPreferenceController(mContext); + mController = new WifiEnhancedMacRandomizationPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test - public void onPreferenceChanged_enabled_shouldTurnOnNonPersistentRandomization() { + public void onPreferenceChanged_enabled_shouldTurnOnEnhancedRandomization() { mController.onPreferenceChange(mPreference, true /* new value */); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(1); } @Test - public void onPreferenceChanged_disabled_shouldTurnOffNonPersistentRandomization() { + public void onPreferenceChanged_disabled_shouldTurnOffEnhancedRandomization() { mController.onPreferenceChange(mPreference, false /* new value */); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(0); } @Test public void updateState_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 1); mController.updateState(mPreference); verify(mPreference).setChecked(true); @@ -86,7 +86,7 @@ public class WifiNonPersistentMacRandomizationPreferenceControllerTest { @Test public void updateState_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0); mController.updateState(mPreference); verify(mPreference).setChecked(false); @@ -97,7 +97,7 @@ public class WifiNonPersistentMacRandomizationPreferenceControllerTest { mController.onDeveloperOptionsSwitchDisabled(); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(0); assertThat(mPreference.isChecked()).isFalse(); From 88703322a5310b58b9e07b30b1832fc7cf473877 Mon Sep 17 00:00:00 2001 From: Daniel Chapin Date: Mon, 12 Jul 2021 22:54:21 +0000 Subject: [PATCH 10/17] Revert "Rename Enhanced MAC Randomization to Non-Persistent" Revert submission 15050857-RenameEnhancedMac Reason for revert: Droidfood blocking Bug: 193375403 Reverted Changes: I5d647a666:Rename Enhanced MAC Randomization to Non-Persisten... I48a326f98:Update old terminology for Non-persistent Mac Rand... Change-Id: Ic6ff02dad064f8d8c7dbaab51c658da12a4d8555 (cherry picked from commit e7cb2762f908d8cfc96b39c46fcf4e03efc07e5b) --- .../DevelopmentSettingsDashboardFragment.java | 2 +- ...MacRandomizationPreferenceController.java} | 22 ++++++++--------- ...andomizationPreferenceControllerTest.java} | 24 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) rename src/com/android/settings/development/{WifiNonPersistentMacRandomizationPreferenceController.java => WifiEnhancedMacRandomizationPreferenceController.java} (71%) rename tests/robotests/src/com/android/settings/development/{WifiNonPersistentMacRandomizationPreferenceControllerTest.java => WifiEnhancedMacRandomizationPreferenceControllerTest.java} (76%) diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java index c02ae42b376..94b67aa76bb 100644 --- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java +++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java @@ -505,7 +505,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra controllers.add(new WifiDisplayCertificationPreferenceController(context)); controllers.add(new WifiVerboseLoggingPreferenceController(context)); controllers.add(new WifiScanThrottlingPreferenceController(context)); - controllers.add(new WifiNonPersistentMacRandomizationPreferenceController(context)); + controllers.add(new WifiEnhancedMacRandomizationPreferenceController(context)); controllers.add(new MobileDataAlwaysOnPreferenceController(context)); controllers.add(new TetheringHardwareAccelPreferenceController(context)); controllers.add(new BluetoothDeviceNoNamePreferenceController(context)); diff --git a/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java b/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java similarity index 71% rename from src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java rename to src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java index 3f6d775c0b7..af44f5b2020 100644 --- a/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceController.java +++ b/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceController.java @@ -26,30 +26,30 @@ import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.development.DeveloperOptionsPreferenceController; /** - * Developer option controller for non-persistent MAC randomization. + * Developer option controller for enhanced MAC randomization. */ -public class WifiNonPersistentMacRandomizationPreferenceController +public class WifiEnhancedMacRandomizationPreferenceController extends DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener, PreferenceControllerMixin { - private static final String WIFI_NON_PERSISTENT_MAC_RANDOMIZATION_KEY = - "wifi_non_persistent_mac_randomization"; - private static final String NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG = - "non_persistent_mac_randomization_force_enabled"; + private static final String WIFI_ENHANCED_MAC_RANDOMIZATION_KEY = + "wifi_enhanced_mac_randomization"; + private static final String ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG = + "enhanced_mac_randomization_force_enabled"; - public WifiNonPersistentMacRandomizationPreferenceController(Context context) { + public WifiEnhancedMacRandomizationPreferenceController(Context context) { super(context); } @Override public String getPreferenceKey() { - return WIFI_NON_PERSISTENT_MAC_RANDOMIZATION_KEY; + return WIFI_ENHANCED_MAC_RANDOMIZATION_KEY; } @Override public boolean onPreferenceChange(Preference preference, Object newValue) { int isEnabledInt = ((Boolean) newValue) ? 1 : 0; Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, isEnabledInt); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, isEnabledInt); return true; } @@ -57,7 +57,7 @@ public class WifiNonPersistentMacRandomizationPreferenceController public void updateState(Preference preference) { boolean enabled = false; if (Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0) == 1) { + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0) == 1) { enabled = true; } ((SwitchPreference) mPreference).setChecked(enabled); @@ -67,7 +67,7 @@ public class WifiNonPersistentMacRandomizationPreferenceController protected void onDeveloperOptionsSwitchDisabled() { super.onDeveloperOptionsSwitchDisabled(); Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0); ((SwitchPreference) mPreference).setChecked(false); } } diff --git a/tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java similarity index 76% rename from tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java rename to tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java index b654387f9ef..25e5a2274f1 100644 --- a/tests/robotests/src/com/android/settings/development/WifiNonPersistentMacRandomizationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java @@ -36,48 +36,48 @@ import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; @RunWith(RobolectricTestRunner.class) -public class WifiNonPersistentMacRandomizationPreferenceControllerTest { - private static final String NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG = - "non_persistent_mac_randomization_force_enabled"; +public class WifiEnhancedMacRandomizationPreferenceControllerTest { + private static final String ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG = + "enhanced_mac_randomization_force_enabled"; @Mock private SwitchPreference mPreference; @Mock private PreferenceScreen mPreferenceScreen; private Context mContext; - private WifiNonPersistentMacRandomizationPreferenceController mController; + private WifiEnhancedMacRandomizationPreferenceController mController; @Before public void setup() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; - mController = new WifiNonPersistentMacRandomizationPreferenceController(mContext); + mController = new WifiEnhancedMacRandomizationPreferenceController(mContext); when(mPreferenceScreen.findPreference(mController.getPreferenceKey())) .thenReturn(mPreference); mController.displayPreference(mPreferenceScreen); } @Test - public void onPreferenceChanged_enabled_shouldTurnOnNonPersistentRandomization() { + public void onPreferenceChanged_enabled_shouldTurnOnEnhancedRandomization() { mController.onPreferenceChange(mPreference, true /* new value */); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(1); } @Test - public void onPreferenceChanged_disabled_shouldTurnOffNonPersistentRandomization() { + public void onPreferenceChanged_disabled_shouldTurnOffEnhancedRandomization() { mController.onPreferenceChange(mPreference, false /* new value */); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(0); } @Test public void updateState_preferenceShouldBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 1); mController.updateState(mPreference); verify(mPreference).setChecked(true); @@ -86,7 +86,7 @@ public class WifiNonPersistentMacRandomizationPreferenceControllerTest { @Test public void updateState_preferenceShouldNotBeChecked() { Settings.Global.putInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, 0); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0); mController.updateState(mPreference); verify(mPreference).setChecked(false); @@ -97,7 +97,7 @@ public class WifiNonPersistentMacRandomizationPreferenceControllerTest { mController.onDeveloperOptionsSwitchDisabled(); int mode = Settings.Global.getInt(mContext.getContentResolver(), - NON_PERSISTENT_MAC_RANDOMIZATION_FEATURE_FLAG, -1); + ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, -1); assertThat(mode).isEqualTo(0); assertThat(mPreference.isChecked()).isFalse(); From 9514607aa19da846f5aca0f3d5bddea63f0da77f Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Thu, 12 Aug 2021 17:04:48 +0000 Subject: [PATCH 11/17] Revert "UWB: Re-enable UWB toggle" This reverts commit 7437b1f07efe02bdd11921e2ee4c009088a0f368. Reason for revert: Reverting until root cause of b/196317865 is identified. Bug: b/196317865 Test: Compiles Change-Id: I6dfed998c4387a54dac8d41ed65c5a30752ed290 (cherry picked from commit 2e593b378466de933781e015076a292b4963c4e5) --- res/xml/connected_devices_advanced.xml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml index 85e4a762429..3ff7d9975f8 100644 --- a/res/xml/connected_devices_advanced.xml +++ b/res/xml/connected_devices_advanced.xml @@ -65,13 +65,6 @@ android:icon="@drawable/ic_folder_vd_theme_24" android:title="@string/bluetooth_show_files_received_via_bluetooth"/> - - From c1f0adeeafdd45c7d09e02f7318ad9e528e31945 Mon Sep 17 00:00:00 2001 From: Bryce Lee Date: Thu, 16 Sep 2021 06:11:31 +0000 Subject: [PATCH 12/17] Revert "Delete SmartAutoRotatePreference and move callback logic to controller" This reverts commit c69bf781817effaacea04299007e06c62de1cc4b. Reason for revert: b/200111886 Change-Id: I232fef4ddef955223140db606d4ed6a5e8c8caf6 (cherry picked from commit 1bb8507b75db55ead34cb9e5818973d63ab1c2f8) --- .../display/SmartAutoRotatePreference.java | 59 +++++++++++++++++++ .../SmartAutoRotatePreferenceController.java | 15 +---- 2 files changed, 61 insertions(+), 13 deletions(-) create mode 100644 src/com/android/settings/display/SmartAutoRotatePreference.java diff --git a/src/com/android/settings/display/SmartAutoRotatePreference.java b/src/com/android/settings/display/SmartAutoRotatePreference.java new file mode 100644 index 00000000000..32b411d71a4 --- /dev/null +++ b/src/com/android/settings/display/SmartAutoRotatePreference.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2021 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.display; + +import android.content.Context; +import android.util.AttributeSet; + +import com.android.internal.view.RotationPolicy; +import com.android.settingslib.PrimarySwitchPreference; + +/** + * component for the display settings auto rotate toggle + */ +public class SmartAutoRotatePreference extends PrimarySwitchPreference { + + private RotationPolicy.RotationPolicyListener mRotationPolicyListener; + + public SmartAutoRotatePreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + public void onAttached() { + super.onAttached(); + if (mRotationPolicyListener == null) { + mRotationPolicyListener = new RotationPolicy.RotationPolicyListener() { + @Override + public void onChange() { + setChecked(!RotationPolicy.isRotationLocked(getContext())); + } + }; + } + RotationPolicy.registerRotationPolicyListener(getContext(), + mRotationPolicyListener); + } + + @Override + public void onDetached() { + super.onDetached(); + if (mRotationPolicyListener != null) { + RotationPolicy.unregisterRotationPolicyListener(getContext(), + mRotationPolicyListener); + } + } +} diff --git a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java index 2e77d34cd0c..be47caee177 100644 --- a/src/com/android/settings/display/SmartAutoRotatePreferenceController.java +++ b/src/com/android/settings/display/SmartAutoRotatePreferenceController.java @@ -22,7 +22,6 @@ import static android.provider.Settings.Secure.CAMERA_AUTOROTATE; import static com.android.settings.display.SmartAutoRotateController.hasSufficientPermission; import static com.android.settings.display.SmartAutoRotateController.isRotationResolverServiceAvailable; -import android.text.TextUtils; import android.app.settings.SettingsEnums; import android.content.BroadcastReceiver; import android.content.Context; @@ -80,16 +79,6 @@ public class SmartAutoRotatePreferenceController extends TogglePreferenceControl ? AVAILABLE : UNSUPPORTED_ON_DEVICE; } - @Override - public boolean isSliceable() { - return TextUtils.equals(getPreferenceKey(), "auto_rotate"); - } - - @Override - public boolean isPublicSlice() { - return true; - } - @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); @@ -111,7 +100,7 @@ public class SmartAutoRotatePreferenceController extends TogglePreferenceControl @Override public void onChange() { if (mPreference != null) { - updateState(mPreference); + refreshSummary(mPreference); } } }; @@ -174,4 +163,4 @@ public class SmartAutoRotatePreferenceController extends TogglePreferenceControl } return mContext.getString(activeStringId); } -} \ No newline at end of file +} From 6078708013d56359f2a7d1bca14086a6bd1b6684 Mon Sep 17 00:00:00 2001 From: Daniel Chapin Date: Mon, 1 Nov 2021 19:36:00 +0000 Subject: [PATCH 13/17] Revert "Update animation for fingerprint edu page" Revert submission 16091075-update_lottie_fp_edu Reason for revert: Droidfood Blocking Bug: 204719520 Reverted Changes: I0c3b1ad93:Update animation for fingerprint edu page Id07ee17fa:Update animation for fingerprint edu page Change-Id: I0f301491c2b526443a40b916ac2d98093d80a759 (cherry picked from commit ba0a012b5783c71ff1f589949fbbde3a41d20b54) --- .../fingerprint_enroll_find_sensor_base.xml | 23 ------- res/raw/fingerprint_edu_lottie.json | 0 res/raw/fingerprint_edu_lottie_portrait.json | 0 .../FingerprintEnrollFindSensor.java | 67 +------------------ 4 files changed, 1 insertion(+), 89 deletions(-) delete mode 100644 res/raw/fingerprint_edu_lottie.json delete mode 100644 res/raw/fingerprint_edu_lottie_portrait.json diff --git a/res/layout/fingerprint_enroll_find_sensor_base.xml b/res/layout/fingerprint_enroll_find_sensor_base.xml index da7fc309711..62203f71c81 100644 --- a/res/layout/fingerprint_enroll_find_sensor_base.xml +++ b/res/layout/fingerprint_enroll_find_sensor_base.xml @@ -17,7 +17,6 @@ - - - - diff --git a/res/raw/fingerprint_edu_lottie.json b/res/raw/fingerprint_edu_lottie.json deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/res/raw/fingerprint_edu_lottie_portrait.json b/res/raw/fingerprint_edu_lottie_portrait.json deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java index 64e066ec00c..3cea9629069 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollFindSensor.java @@ -21,14 +21,13 @@ import android.content.Intent; import android.hardware.fingerprint.FingerprintManager; import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; import android.os.Bundle; -import android.view.OrientationEventListener; -import android.view.Surface; import android.view.View; import android.view.View.OnClickListener; import android.view.accessibility.AccessibilityManager; import androidx.annotation.Nullable; +import com.airbnb.lottie.LottieAnimationView; import com.android.settings.R; import com.android.settings.Utils; import com.android.settings.biometrics.BiometricEnrollBase; @@ -36,7 +35,6 @@ import com.android.settings.biometrics.BiometricEnrollSidecar; import com.android.settings.biometrics.BiometricUtils; import com.android.settings.password.ChooseLockSettingsHelper; -import com.airbnb.lottie.LottieAnimationView; import com.google.android.setupcompat.template.FooterBarMixin; import com.google.android.setupcompat.template.FooterButton; @@ -54,10 +52,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements private FingerprintEnrollSidecar mSidecar; private boolean mNextClicked; private boolean mCanAssumeUdfps; - private boolean mCanAssumeSidefps; - - private OrientationEventListener mOrientationEventListener; - private int mPreviousRotation = 0; @Override protected void onCreate(Bundle savedInstanceState) { @@ -67,7 +61,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements final List props = fingerprintManager.getSensorPropertiesInternal(); mCanAssumeUdfps = props != null && props.size() == 1 && props.get(0).isAnyUdfpsType(); - mCanAssumeSidefps = props != null && props.size() == 1 && props.get(0).isAnySidefpsType(); setContentView(getContentView()); mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class); mFooterBarMixin.setSecondaryButton( @@ -79,8 +72,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements .build() ); - listenOrientationEvent(); - if (mCanAssumeUdfps) { setHeaderText(R.string.security_settings_udfps_enroll_find_sensor_title); setDescriptionText(R.string.security_settings_udfps_enroll_find_sensor_message); @@ -99,28 +90,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements lottieAnimationView.setAnimation(R.raw.udfps_edu_a11y_lottie); } - } else if (mCanAssumeSidefps) { - setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title); - setDescriptionText(R.string.security_settings_fingerprint_enroll_find_sensor_message); - final LottieAnimationView lottieAnimationView = findViewById(R.id.illustration_lottie); - final LottieAnimationView lottieAnimationViewPortrait = - findViewById(R.id.illustration_lottie_portrait); - final int rotation = getApplicationContext().getDisplay().getRotation(); - switch(rotation) { - case Surface.ROTATION_90: - lottieAnimationView.setVisibility(View.GONE); - lottieAnimationViewPortrait.setVisibility(View.VISIBLE); - break; - case Surface.ROTATION_270: - lottieAnimationView.setVisibility(View.GONE); - lottieAnimationViewPortrait.setVisibility(View.VISIBLE); - lottieAnimationViewPortrait.setRotation(180); - break; - default: - lottieAnimationView.setVisibility(View.VISIBLE); - lottieAnimationViewPortrait.setVisibility(View.GONE); - break; - } } else { setHeaderText(R.string.security_settings_fingerprint_enroll_find_sensor_title); setDescriptionText(R.string.security_settings_fingerprint_enroll_find_sensor_message); @@ -251,7 +220,6 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements @Override protected void onDestroy() { - stopListenOrientationEvent(); super.onDestroy(); if (mAnimation != null) { mAnimation.stopAnimation(); @@ -329,37 +297,4 @@ public class FingerprintEnrollFindSensor extends BiometricEnrollBase implements public int getMetricsCategory() { return SettingsEnums.FINGERPRINT_FIND_SENSOR; } - - private void listenOrientationEvent() { - if (!mCanAssumeSidefps) { - // Do nothing if the device doesn't support SideFPS. - return; - } - mOrientationEventListener = new OrientationEventListener(this) { - @Override - public void onOrientationChanged(int orientation) { - final int currentRotation = getDisplay().getRotation(); - if ((mPreviousRotation == Surface.ROTATION_90 - && currentRotation == Surface.ROTATION_270) || ( - mPreviousRotation == Surface.ROTATION_270 - && currentRotation == Surface.ROTATION_90)) { - mPreviousRotation = currentRotation; - recreate(); - } - } - }; - mOrientationEventListener.enable(); - mPreviousRotation = getDisplay().getRotation(); - } - - private void stopListenOrientationEvent() { - if (!mCanAssumeSidefps) { - // Do nothing if the device doesn't support SideFPS. - return; - } - if (mOrientationEventListener != null) { - mOrientationEventListener.disable(); - } - mOrientationEventListener = null; - } } From 2953db1d2caddca27e4876cb6980ae0f42c411a0 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 24 May 2022 18:00:34 +0800 Subject: [PATCH 14/17] Fix crash for DefaultSubscriptionController setSummaryProvider() is used instead of setSummary() in Ia24d88817c99db7ed3fc264dbc9c10e0a09d8a39, but there is still a place using the setSummary(), mixing these two will lead to crash. Change it to setSummaryProvider() to prevent crash. Fix: 233295254 Fix: 233712251 Test: manual Change-Id: I4627545711b848009c3bd7179f0368ff82e62697 (cherry picked from commit 2e34038233a99cefbf432d2b68851048246dfecb) Merged-In: I4627545711b848009c3bd7179f0368ff82e62697 --- .../network/telephony/DefaultSubscriptionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index 5511829a61a..a3a281c4198 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -168,8 +168,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere if (subs.size() == 1) { mPreference.setEnabled(false); - mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName( - subs.get(0), mContext)); + mPreference.setSummaryProvider(pref -> + SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext)); return; } From c3efb1d35c8752cef80011836facb76ab0c6e1e0 Mon Sep 17 00:00:00 2001 From: Chaohui Wang Date: Tue, 24 May 2022 18:00:34 +0800 Subject: [PATCH 15/17] Fix crash for DefaultSubscriptionController setSummaryProvider() is used instead of setSummary() in Ia24d88817c99db7ed3fc264dbc9c10e0a09d8a39, but there is still a place using the setSummary(), mixing these two will lead to crash. Change it to setSummaryProvider() to prevent crash. Fix: 233295254 Fix: 233712251 Test: manual Change-Id: I4627545711b848009c3bd7179f0368ff82e62697 (cherry picked from commit 2e34038233a99cefbf432d2b68851048246dfecb) Merged-In: I4627545711b848009c3bd7179f0368ff82e62697 --- .../network/telephony/DefaultSubscriptionController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java index 5511829a61a..a3a281c4198 100644 --- a/src/com/android/settings/network/telephony/DefaultSubscriptionController.java +++ b/src/com/android/settings/network/telephony/DefaultSubscriptionController.java @@ -168,8 +168,8 @@ public abstract class DefaultSubscriptionController extends TelephonyBasePrefere if (subs.size() == 1) { mPreference.setEnabled(false); - mPreference.setSummary(SubscriptionUtil.getUniqueSubscriptionDisplayName( - subs.get(0), mContext)); + mPreference.setSummaryProvider(pref -> + SubscriptionUtil.getUniqueSubscriptionDisplayName(subs.get(0), mContext)); return; } From 8cef068117d15802595a558281c1d1efe3d62da2 Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 23 Jun 2022 12:12:23 +0800 Subject: [PATCH 16/17] Make bluetooth not discoverable via large screen deep link flow Deep links on large screen devices starts a homepage activity on the left pane, and then starts the target activity on the right pane. This flow overrides the calling package, and the target activity can't know who initially calls it. Thus, we store the initial calling package in the intent, so the Connected devices page is able to make bluetooth not discoverable when it's called from unintended apps on large screen devices. Bug: 234440688 Test: robotest, manual Change-Id: I4ddcd4e083c002ece9d10aabdb4af4a41de55ce7 Merged-In: I4ddcd4e083c002ece9d10aabdb4af4a41de55ce7 (cherry picked from commit 5df14831b8d0bbae062c644cfa987378ea2ca9d4) Merged-In: I4ddcd4e083c002ece9d10aabdb4af4a41de55ce7 --- src/com/android/settings/SettingsActivity.java | 15 +++++++++++++++ .../ConnectedDeviceDashboardFragment.java | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/SettingsActivity.java b/src/com/android/settings/SettingsActivity.java index f9515017406..4341851c3fa 100644 --- a/src/com/android/settings/SettingsActivity.java +++ b/src/com/android/settings/SettingsActivity.java @@ -70,6 +70,7 @@ import com.android.settings.homepage.DeepLinkHomepageActivityInternal; import com.android.settings.homepage.SettingsHomepageActivity; import com.android.settings.homepage.TopLevelSettings; import com.android.settings.overlay.FeatureFactory; +import com.android.settings.password.PasswordUtils; import com.android.settings.wfd.WifiDisplaySettings; import com.android.settings.widget.SettingsMainSwitchBar; import com.android.settingslib.core.instrumentation.Instrumentable; @@ -154,6 +155,7 @@ public class SettingsActivity extends SettingsBaseActivity public static final String EXTRA_IS_FROM_SLICE = "is_from_slice"; public static final String EXTRA_USER_HANDLE = "user_handle"; + public static final String EXTRA_INITIAL_CALLING_PACKAGE = "initial_calling_package"; /** * Personal or Work profile tab of {@link ProfileSelectFragment} @@ -418,6 +420,8 @@ public class SettingsActivity extends SettingsBaseActivity } private boolean tryStartTwoPaneDeepLink(Intent intent) { + intent.putExtra(EXTRA_INITIAL_CALLING_PACKAGE, PasswordUtils.getCallingAppPackageName( + getActivityToken())); final Intent trampolineIntent; if (intent.getBooleanExtra(EXTRA_IS_FROM_SLICE, false)) { // Get menu key for slice deep link case. @@ -505,6 +509,17 @@ public class SettingsActivity extends SettingsBaseActivity return true; } + /** Returns the initial calling package name that launches the activity. */ + public String getInitialCallingPackage() { + String callingPackage = PasswordUtils.getCallingAppPackageName(getActivityToken()); + if (!TextUtils.equals(callingPackage, getPackageName())) { + return callingPackage; + } + + String initialCallingPackage = getIntent().getStringExtra(EXTRA_INITIAL_CALLING_PACKAGE); + return TextUtils.isEmpty(initialCallingPackage) ? callingPackage : initialCallingPackage; + } + /** Returns the initial fragment name that the activity will launch. */ @VisibleForTesting public String getInitialFragmentName(Intent intent) { diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java index 7e6eefe2e41..ea8a5f560f9 100644 --- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java +++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java @@ -25,9 +25,9 @@ import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.settings.R; +import com.android.settings.SettingsActivity; import com.android.settings.core.SettingsUIDeviceConfig; import com.android.settings.dashboard.DashboardFragment; -import com.android.settings.password.PasswordUtils; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.slices.SlicePreferenceController; import com.android.settingslib.search.SearchIndexable; @@ -71,8 +71,8 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment { super.onAttach(context); final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI, SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true); - String callingAppPackageName = PasswordUtils.getCallingAppPackageName( - getActivity().getActivityToken()); + String callingAppPackageName = ((SettingsActivity) getActivity()) + .getInitialCallingPackage(); String action = getIntent() != null ? getIntent().getAction() : ""; if (DEBUG) { Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName From 34dac9cb7394b5bea864b23e28621296fdaf7f9b Mon Sep 17 00:00:00 2001 From: SongFerngWang Date: Thu, 7 Jul 2022 06:21:50 +0800 Subject: [PATCH 17/17] [MEP] Hide the preferred SIM dialog when the user has replaced the SIM Since there is the race condition and it causes UI hides the preferred SIM dialog. Therefore, to hide the preferred SIM dialog under the specific condition which the user has replaced the SIM during the SIM switching. Bug: 238061853 Test: Manually testing. Device has the psim+esim and the esim's mobile data on. The tester disables the esim and then UI shows the preferred SIM dialog. Change-Id: I01e7d60170c5053730fd3113abd914fb5c0d11c9 (cherry picked from commit 286dce6b6ed8f06d8599c2a3de34c36ddd4445dd) Merged-In: I01e7d60170c5053730fd3113abd914fb5c0d11c9 --- .../SubscriptionActionDialogActivity.java | 14 +++++++++++++- .../ToggleSubscriptionDialogActivity.java | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java index c509bac575c..391158f065b 100644 --- a/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java +++ b/src/com/android/settings/network/telephony/SubscriptionActionDialogActivity.java @@ -60,8 +60,20 @@ public class SubscriptionActionDialogActivity extends FragmentActivity { * @param message The string content should be displayed in the progress dialog. */ protected void showProgressDialog(String message) { + showProgressDialog(message,false); + } + + /** + * Displays a loading dialog. + * + * @param message The string content should be displayed in the progress dialog. + * @param updateIfNeeded is whether to update the progress state in the SharedPreferences. + */ + protected void showProgressDialog(String message, boolean updateIfNeeded) { ProgressDialogFragment.show(getFragmentManager(), message, null); - setProgressState(PROGRESS_IS_SHOWING); + if (updateIfNeeded) { + setProgressState(PROGRESS_IS_SHOWING); + } } /** Dismisses the loading dialog. */ diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java index f5f18b4b9ee..a878cb3ebd3 100644 --- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java +++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java @@ -220,8 +220,8 @@ public class ToggleSubscriptionDialogActivity extends SubscriptionActionDialogAc showProgressDialog( getString( R.string.sim_action_switch_sub_dialog_progress, - SubscriptionUtil.getUniqueSubscriptionDisplayName( - mSubInfo, this))); + SubscriptionUtil.getUniqueSubscriptionDisplayName(mSubInfo, this)), + removedSubInfo != null ? true : false); if (mIsEsimOperation) { mSwitchToEuiccSubscriptionSidecar.run(mSubInfo.getSubscriptionId(), UiccSlotUtil.INVALID_PORT_ID,