android / car-samples

Multiple samples showing best practices for car app development on both Android Auto and Android Automotive OS.
Apache License 2.0
358 stars 166 forks source link

CAR_MILEAGE permission not availble #20

Open milanchauhanajmerainfotech opened 3 years ago

milanchauhanajmerainfotech commented 3 years ago

Hello

I am getting a security exceptions when I trying to get the value of ODOMETER using VehiclePropertyIds.PERF_ODOMETER, saving that requires android.car.permission.CAR_MILEAGE permission for access, But I add permission in menifest.xml and requesting permission at run time as well

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.carapihelloworld">

    <uses-permission android:name="android.car.permission.CAR_SPEED" />
    <uses-permission android:name="android.car.permission.CAR_POWERTRAIN" />
    <uses-permission android:name="android.car.permission.CAR_MILEAGE" />
    <uses-permission android:name="android.car.permission.PERMISSION_READ_DISPLAY_UNITS" />
    <uses-permission android:name="android.car.permission.PERMISSION_VENDOR_EXTENSION" />
    <uses-permission android:name="android.car.permission.READ_CAR_DISPLAY_UNITS" />
    <uses-permission android:name="android.car.permission.PERMISSION_CONTROL_DISPLAY_UNITS" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>
if (checkSelfPermission("android.car.permission.CAR_MILEAGE") != PackageManager.PERMISSION_GRANTED) {
          requestPermissions(new String[]{"android.car.permission.CAR_MILEAGE", Car.PERMISSION_CONTROL_DISPLAY_UNITS , Car.PERMISSION_SPEED, Car.PERMISSION_POWERTRAIN, Car.PERMISSION_READ_DISPLAY_UNITS}, REQUEST_CODE_ASK_PERMISSIONS);
      } else {
          initCarApi();
      }

try {
        CarPropertyValue carProperty = mCarPropertyManager.getProperty(VehiclePropertyIds.PERF_ODOMETER, DEFAULT_KEYS_SEARCH_GLOBAL);
        Log.d(TAG, "MilanMistry: " + carProperty.getValue());
    } catch (SecurityException e) {
        Log.d(TAG, "MilanMistry: " + e.getMessage());
    }

And I check Car.java class from android.car library there in no permission like android.car.permission.CAR_MILEAGE, But in official document suggesting this permission

public static final String APP_FOCUS_SERVICE = "app_focus";
    public static final String AUDIO_SERVICE = "audio";
    public static final String CAR_CONFIGURATION_SERVICE = "configuration";
    public static final String CAR_EXTRA_MEDIA_PACKAGE = "android.car.intent.extra.MEDIA_PACKAGE";
    public static final String CAR_INTENT_ACTION_MEDIA_TEMPLATE = "android.car.intent.action.MEDIA_TEMPLATE";
    public static final String CAR_NAVIGATION_SERVICE = "car_navigation_service";
    public static final String CAR_UX_RESTRICTION_SERVICE = "uxrestriction";
    public static final int CONNECTION_TYPE_EMBEDDED = 5;
    public static final String INFO_SERVICE = "info";
    public static final String PACKAGE_SERVICE = "package";
    public static final String PERMISSION_CAR_CONTROL_AUDIO_SETTINGS = "android.car.permission.CAR_CONTROL_AUDIO_SETTINGS";
    public static final String PERMISSION_CAR_CONTROL_AUDIO_VOLUME = "android.car.permission.CAR_CONTROL_AUDIO_VOLUME";
    public static final String PERMISSION_CAR_INFO = "android.car.permission.CAR_INFO";
    public static final String PERMISSION_CAR_NAVIGATION_MANAGER = "android.car.permission.CAR_NAVIGATION_MANAGER";
    public static final String PERMISSION_CONTROL_DISPLAY_UNITS = "android.car.permission.CONTROL_CAR_DISPLAY_UNITS";
    public static final String PERMISSION_CONTROL_INTERIOR_LIGHTS = "android.car.permission.CONTROL_CAR_INTERIOR_LIGHTS";
    public static final String PERMISSION_ENERGY = "android.car.permission.CAR_ENERGY";
    public static final String PERMISSION_ENERGY_PORTS = "android.car.permission.CAR_ENERGY_PORTS";
    public static final String PERMISSION_EXTERIOR_ENVIRONMENT = "android.car.permission.CAR_EXTERIOR_ENVIRONMENT";
    public static final String PERMISSION_IDENTIFICATION = "android.car.permission.CAR_IDENTIFICATION";
    public static final String PERMISSION_POWERTRAIN = "android.car.permission.CAR_POWERTRAIN";
    public static final String PERMISSION_READ_DISPLAY_UNITS = "android.car.permission.READ_CAR_DISPLAY_UNITS";
    public static final String PERMISSION_READ_INTERIOR_LIGHTS = "android.car.permission.READ_CAR_INTERIOR_LIGHTS";
    public static final String PERMISSION_READ_STEERING_STATE = "android.car.permission.READ_CAR_STEERING";
    public static final String PERMISSION_SPEED = "android.car.permission.CAR_SPEED";
    public static final String PROPERTY_SERVICE = "property";