Check for available rotation resolver service and camera permission before showing setting for face based auto-rotation
Test: locally with crosshatch & make -j64 RunSettingsRoboTests ROBOTEST_FILTER="com.android.settings.display.SmartAutoRotateControllerTest" Bug: 172857585 Change-Id: I825b0c2471c71a3de59532b39a47c5442f234fb5
This commit is contained in:
@@ -15,8 +15,10 @@
|
||||
*/
|
||||
package com.android.settings.display;
|
||||
|
||||
import static com.android.settings.display.SmartAutoRotateController.hasSufficientPermission;
|
||||
import static com.android.settings.display.SmartAutoRotateController.isRotationResolverServiceAvailable;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -31,16 +33,12 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.Indexable;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
|
||||
/**
|
||||
* Preference fragment used to auto rotation
|
||||
* Preference fragment used for auto rotation
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@SearchIndexable
|
||||
@@ -51,7 +49,6 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
|
||||
private AutoRotateSwitchBarController mSwitchBarController;
|
||||
private static final String FACE_SWITCH_PREFERENCE_ID = "face_based_rotate";
|
||||
private static final String SMART_AUTO_ROTATE_CONTROLLER_KEY = "auto_rotate";
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
@@ -69,6 +66,12 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
switchBar.show();
|
||||
mSwitchBarController = new AutoRotateSwitchBarController(activity, switchBar,
|
||||
getSettingsLifecycle());
|
||||
final Preference footerPreference = findPreference(FooterPreference.KEY_FOOTER);
|
||||
if (footerPreference != null) {
|
||||
footerPreference.setTitle(Html.fromHtml(getString(R.string.smart_rotate_text_headline),
|
||||
Html.FROM_HTML_MODE_COMPACT));
|
||||
footerPreference.setVisible(isRotationResolverServiceAvailable(activity));
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -82,7 +85,7 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
mSwitchBarController.onChange();
|
||||
final boolean isLocked = RotationPolicy.isRotationLocked(getContext());
|
||||
final Preference preference = findPreference(FACE_SWITCH_PREFERENCE_ID);
|
||||
if (preference != null) {
|
||||
if (preference != null && hasSufficientPermission(getContext())) {
|
||||
preference.setEnabled(!isLocked);
|
||||
}
|
||||
}
|
||||
@@ -90,17 +93,11 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
}
|
||||
RotationPolicy.registerRotationPolicyListener(getPrefContext(),
|
||||
mRotationPolicyListener);
|
||||
|
||||
findPreference(FooterPreference.KEY_FOOTER).setTitle(
|
||||
Html.fromHtml(getString(R.string.smart_rotate_text_headline),
|
||||
Html.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (mRotationPolicyListener != null) {
|
||||
RotationPolicy.unregisterRotationPolicyListener(getPrefContext(),
|
||||
mRotationPolicyListener);
|
||||
@@ -112,36 +109,11 @@ public class SmartAutoRotatePreferenceFragment extends DashboardFragment {
|
||||
return SettingsEnums.DISPLAY_AUTO_ROTATE_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(
|
||||
Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(
|
||||
new SmartAutoRotatePreferenceController(context, SMART_AUTO_ROTATE_CONTROLLER_KEY));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return TAG;
|
||||
}
|
||||
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider(R.xml.auto_rotate_settings) {
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
new BaseSearchIndexProvider(R.xml.auto_rotate_settings);
|
||||
}
|
||||
|
Reference in New Issue
Block a user