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:
@@ -17,9 +17,15 @@ package com.android.settings.display;
|
||||
|
||||
import static android.provider.Settings.Secure.CAMERA_AUTOROTATE;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.provider.Settings;
|
||||
import android.service.rotationresolver.RotationResolverService;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@@ -43,13 +49,17 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return !RotationPolicy.isRotationLocked(mContext)
|
||||
if (!isRotationResolverServiceAvailable(mContext)) {
|
||||
return UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
return !RotationPolicy.isRotationLocked(mContext) && hasSufficientPermission(mContext)
|
||||
? AVAILABLE : DISABLED_DEPENDENT_SETTING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return Settings.Secure.getInt(mContext.getContentResolver(),
|
||||
return hasSufficientPermission(mContext) && Settings.Secure.getInt(
|
||||
mContext.getContentResolver(),
|
||||
CAMERA_AUTOROTATE, 0) == 1;
|
||||
}
|
||||
|
||||
@@ -62,4 +72,24 @@ public class SmartAutoRotateController extends TogglePreferenceController implem
|
||||
isChecked ? 1 : 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
static boolean isRotationResolverServiceAvailable(Context context) {
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
final String resolvePackage = packageManager.getRotationResolverPackageName();
|
||||
if (TextUtils.isEmpty(resolvePackage)) {
|
||||
return false;
|
||||
}
|
||||
final Intent intent = new Intent(RotationResolverService.SERVICE_INTERFACE).setPackage(
|
||||
resolvePackage);
|
||||
final ResolveInfo resolveInfo = packageManager.resolveService(intent,
|
||||
PackageManager.MATCH_SYSTEM_ONLY);
|
||||
return resolveInfo != null && resolveInfo.serviceInfo != null;
|
||||
}
|
||||
|
||||
static boolean hasSufficientPermission(Context context) {
|
||||
final PackageManager packageManager = context.getPackageManager();
|
||||
final String rotationPackage = packageManager.getRotationResolverPackageName();
|
||||
return rotationPackage != null && packageManager.checkPermission(
|
||||
Manifest.permission.CAMERA, rotationPackage) == PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user