- if (!specCameraFeature && hasCameraPermission) {
- // For applications that have not explicitly stated their
- // camera feature requirements, but have requested the camera
- // permission, we are going to give them compatibility treatment
- // of requiring the equivalent to original android devices.
- printf("uses-feature:'android.hardware.camera'\n");
- printf("uses-feature:'android.hardware.camera.autofocus'\n");
+ /* The following blocks handle printing "inferred" uses-features, based
+ * on whether related features or permissions are used by the app.
+ * Note that the various spec*Feature variables denote whether the
+ * relevant tag was *present* in the AndroidManfest, not that it was
+ * present and set to true.
+ */
+ // Camera-related back-compatibility logic
+ if (!specCameraFeature) {
+ if (reqCameraFlashFeature || reqCameraAutofocusFeature) {
+ // if app requested a sub-feature (autofocus or flash) and didn't
+ // request the base camera feature, we infer that it meant to
+ printf("uses-feature:'android.hardware.camera'\n");
+ } else if (hasCameraPermission) {
+ // if app wants to use camera but didn't request the feature, we infer
+ // that it meant to, and further that it wants autofocus
+ // (which was the 1.0 - 1.5 behavior)
+ printf("uses-feature:'android.hardware.camera'\n");
+ if (!specCameraAutofocusFeature) {
+ printf("uses-feature:'android.hardware.camera.autofocus'\n");
+ }
+ }
+ }
+
+ // Location-related back-compatibility logic
+ if (!specLocationFeature &&
+ (hasMockLocPermission || hasCoarseLocPermission || hasGpsPermission ||
+ hasGeneralLocPermission || reqNetworkLocFeature || reqGpsFeature)) {
+ // if app either takes a location-related permission or requests one of the
+ // sub-features, we infer that it also meant to request the base location feature
+ printf("uses-feature:'android.hardware.location'\n");
+ }
+ if (!specGpsFeature && hasGpsPermission) {
+ // if app takes GPS (FINE location) perm but does not request the GPS
+ // feature, we infer that it meant to
+ printf("uses-feature:'android.hardware.location.gps'\n");
+ }
+ if (!specNetworkLocFeature && hasCoarseLocPermission) {
+ // if app takes Network location (COARSE location) perm but does not request the
+ // network location feature, we infer that it meant to
+ printf("uses-feature:'android.hardware.location.network'\n");
+ }
+
+ // Bluetooth-related compatibility logic
+ if (!specBluetoothFeature && hasBluetoothPermission && (targetSdk > 4)) {
+ // if app takes a Bluetooth permission but does not request the Bluetooth
+ // feature, we infer that it meant to
+ printf("uses-feature:'android.hardware.bluetooth'\n");