Small refactor to allow more customization of AutoRotate settings in

extending classes

Bug: 195757480
Test: manual
Change-Id: I8d041933a77d0e6d0118c5e12ed02483ec4b14d5
This commit is contained in:
Alex Florescu
2021-11-19 11:46:49 +00:00
parent 580cc81f11
commit e0169ec1fa
2 changed files with 12 additions and 5 deletions

View File

@@ -63,7 +63,7 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
updateState(mPreference);
}
};
private Preference mPreference;
protected Preference mPreference;
private RotationPolicy.RotationPolicyListener mRotationPolicyListener;
public SmartAutoRotateController(Context context, String preferenceKey) {
@@ -84,10 +84,14 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
if (!isRotationResolverServiceAvailable(mContext)) {
return UNSUPPORTED_ON_DEVICE;
}
return !RotationPolicy.isRotationLocked(mContext) && hasSufficientPermission(mContext)
return !isRotationLocked() && hasSufficientPermission(mContext)
&& !isCameraLocked() && !isPowerSaveMode() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
}
protected boolean isRotationLocked() {
return RotationPolicy.isRotationLocked(mContext);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
@@ -136,7 +140,7 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
@Override
public boolean isChecked() {
return !RotationPolicy.isRotationLocked(mContext) && hasSufficientPermission(mContext)
return !isRotationLocked() && hasSufficientPermission(mContext)
&& !isCameraLocked() && !isPowerSaveMode() && Settings.Secure.getInt(
mContext.getContentResolver(),
CAMERA_AUTOROTATE, 0) == 1;
@@ -163,7 +167,10 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
return R.string.menu_key_display;
}
static boolean isRotationResolverServiceAvailable(Context context) {
/**
* Returns true if there is a {@link RotationResolverService} available
*/
public static boolean isRotationResolverServiceAvailable(Context context) {
final PackageManager packageManager = context.getPackageManager();
final String resolvePackage = packageManager.getRotationResolverPackageName();
if (TextUtils.isEmpty(resolvePackage)) {