1# 程序访问子系统变更说明
2## cl.access_token.1 requestPermissionsFromUser申请位置权限时行为变更
3
4**访问级别**
5
6公开接口
7
8**变更原因**
9
10根据安全隐私要求,地理位置支持使用期间允许的管控能力。位置权限申请使用时,禁止通过弹窗形式授予后台位置权限;
11
12应用如需使用后台位置权限,需要在设置界面由用户手动授予,具体授权方式请参考下文【适配指导】
13
14**变更影响**
15
16涉及权限:
17
18前台位置权限(用于管控应用前台获取位置信息行为):
19
20精确位置权限:[ohos.permission.LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionlocation):允许应用获取设备精确位置信息;需要先申请模糊位置权限才可申请此权限。
21
22模糊位置权限:[ohos.permission.APPROXIMATELY_LOCATION](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionapproximately_location):允许应用获取设备模糊位置信息。
23
24后台位置权限(用于管控应用后台获取位置信息行为):
25
26[ohos.permission.LOCATION_IN_BACKGROUND](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/security/AccessToken/permissions-for-all.md#ohospermissionlocation_in_background):允许应用在后台运行时获取设备位置信息;需要先申请前台位置权限后,才可申请此权限。
27
28具体受影响的弹窗场景见下文:
29
30a) 应用仅申请后台位置权限(前台位置权限未弹窗申请)
31
32变更前:弹出弹窗,点击允许可授予后台位置权限
33
34变更后:不弹窗,不授予后台位置权限
35
36b) 应用仅申请后台位置权限(前台位置权限已授予)
37
38变更前:不弹窗,后台位置权限在第一次授予前台位置权限时同时授予
39
40变更后:不弹窗,不授予后台位置权限
41
42c) 应用同时申请前台位置和后台位置权限
43
44变更前:弹窗展示允许和拒绝选项,选择允许则授予前台位置+后台位置权限
45
46变更后:
47
48API 10及以前:弹窗展示使用期间允许和拒绝选项,选择使用期间允许,仅授予前台位置权限;
49
50API 11及以后:不弹窗,不授予前台位置和后台位置权限
51
52**API level**
53
549
55
56**变更发生版本**
57
58从OpenHarmony SDK 4.1.5.3开始。
59
60**变更的接口/组件**
61
62@ohos.abilityAccessCtrl.d.ts中[requestPermissionsFromUser](../../../application-dev/reference/apis/js-apis-abilityAccessCtrl.md#requestpermissionsfromuser9)接口
63
64**可能影响接口**
65
66| 文件 | 方法 |
67| -------- | -------- |
68| @ohos.geolocation.d.ts | geolocation.on('locationChange') |
69| @ohos.geolocation.d.ts | geolocation.off('locationChange') |
70| @ohos.geolocation.d.ts | geolocation.on('locationServiceState') |
71| @ohos.geolocation.d.ts | geolocation.off('locationServiceState') |
72| @ohos.geolocation.d.ts | geolocation.on('cachedGnssLocationsReporting') |
73| @ohos.geolocation.d.ts | geolocation.off('cachedGnssLocationsReporting') |
74| @ohos.geolocation.d.ts | geolocation.on('gnssStatusChange') |
75| @ohos.geolocation.d.ts | geolocation.off('gnssStatusChange') |
76| @ohos.geolocation.d.ts | geolocation.on('nmeaMessageChange') |
77| @ohos.geolocation.d.ts | geolocation.off('nmeaMessageChange') |
78| @ohos.geolocation.d.ts | geolocation.on('fenceStatusChange') |
79| @ohos.geolocation.d.ts | geolocation.off('fenceStatusChange') |
80| @ohos.geolocation.d.ts | geolocation.getCurrentLocation |
81| @ohos.geolocation.d.ts | geolocation.getLastLocation |
82| @ohos.geolocation.d.ts | geolocation.isLocationEnabled |
83| @ohos.geolocation.d.ts | geolocation.requestEnableLocation |
84| @ohos.geolocation.d.ts | geolocation.isGeoServiceAvailable |
85| @ohos.geolocation.d.ts | geolocation.getAddressesFromLocation |
86| @ohos.geolocation.d.ts | geolocation.getAddressesFromLocationName |
87| @ohos.geolocation.d.ts | geolocation.getCachedGnssLocationsSize |
88| @ohos.geolocation.d.ts | geolocation.flushCachedGnssLocations |
89| @ohos.geolocation.d.ts | geolocation.sendCommand |
90| @ohos.geolocation.d.ts | SatelliteStatusInfo |
91| @ohos.geolocation.d.ts | CachedGnssLocationsRequest |
92| @ohos.geolocation.d.ts | GeofenceRequest |
93| @ohos.geolocation.d.ts | Geofence |
94| @ohos.geolocation.d.ts | ReverseGeoCodeRequest |
95| @ohos.geolocation.d.ts | GeoCodeRequest |
96| @ohos.geolocation.d.ts | GeoAddress |
97| @ohos.geolocation.d.ts | LocationRequest |
98| @ohos.geolocation.d.ts | CurrentLocationRequest |
99| @ohos.geolocation.d.ts | Location |
100| @ohos.geoLocationManager.d.ts | geoLocationManager.on('nmeaMessage') |
101| @ohos.geoLocationManager.d.ts | geoLocationManager.off('nmeaMessage') |
102| @ohos.geoLocationManager.d.ts | geoLocationManager.on('locatingRequiredDataChange') |
103| @ohos.geoLocationManager.d.ts | geoLocationManager.off('locatingRequiredDataChange') |
104| @ohos.geoLocationManager.d.ts | geoLocationManager.getLocatingRequiredData |
105| @ohos.bluetooth.d.ts | bluetooth.startBluetoothDiscovery |
106| @ohos.bluetooth.d.ts | startBLEScan |
107| @ohos.bluetoothManager.d.ts | bluetoothManager.startBluetoothDiscovery |
108| @ohos.bluetoothManager.d.ts | startBLEScan |
109| @ohos.telephony.observer.d.ts | observer.on('cellInfoChange') |
110| @ohos.telephony.radio.d.ts | radio.sendUpdateCellLocationRequest |
111| @ohos.telephony.radio.d.ts | radio.getCellInformation |
112| @system.geolocation.d.ts | GetLocationOption |
113| @system.geolocation.d.ts | SubscribeLocationOption |
114| @system.geolocation.d.ts | geolocation.getLocation |
115| @system.geolocation.d.ts | geolocation.subscribe |
116| @system.geolocation.d.ts | geolocation.unsubscribe |
117| @ohos.wifi.d.ts | wifi.scan |
118| @ohos.wifi.d.ts | wifi.getScanInfos |
119| @ohos.wifi.d.ts | wifi.getDeviceConfigs |
120| @ohos.wifi.d.ts | wifi.getStations |
121| @ohos.wifi.d.ts | wifi.getCurrentGroup |
122| @ohos.wifi.d.ts | wifi.getP2pPeerDevices |
123| @ohos.wifi.d.ts | wifi.p2pConnect |
124| @ohos.wifi.d.ts | wifi.startDiscoverDevices |
125| @ohos.wifi.d.ts | wifi.on('p2pDeviceChange') |
126| @ohos.wifi.d.ts | wifi.off('p2pDeviceChange') |
127| @ohos.wifi.d.ts | wifi.on('p2pPeerDeviceChange') |
128| @ohos.wifi.d.ts | wifi.off('p2pPeerDeviceChange') |
129| @ohos.wifiManager.d.ts | wifiManager.scan |
130| @ohos.wifiManager.d.ts | wifiManager.getScanResults |
131| @ohos.wifiManager.d.ts | wifiManager.getScanResultsSync |
132| @ohos.wifiManager.d.ts | wifiManager.getCandidateConfigs |
133| @ohos.wifiManager.d.ts | wifiManager.getDeviceConfigs |
134| @ohos.wifiManager.d.ts | wifiManager.getStations |
135| @ohos.wifiManager.d.ts | wifiManager.getCurrentGroup |
136| @ohos.wifiManager.d.ts | wifiManager.getP2pPeerDevices |
137| @ohos.wifiManager.d.ts | wifiManager.p2pConnect |
138| @ohos.wifiManager.d.ts | wifiManager.startDiscoverDevices |
139| @ohos.wifiManager.d.ts | wifiManager.getP2pGroups |
140| @ohos.wifiManager.d.ts | wifiManager.on('p2pDeviceChange') |
141| @ohos.wifiManager.d.ts | wifiManager.off('p2pDeviceChange') |
142| @ohos.wifiManager.d.ts | wifiManager.on('p2pPeerDeviceChange') |
143| @ohos.wifiManager.d.ts | wifiManager.off('p2pPeerDeviceChange') |
144
145**适配指导**
146
1471、应用在requestPermissionsFromUser接口中同时申请前台、后台位置权限
148
149    a) 排查应用是否需要后台位置权限,如需要,将接口申请权限行为更改为单独申请前台位置权限
150
151        由:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION', 'ohos.permission.LOCATION_IN_BACKGROUND'], ......)
152        更改为:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION'], ......)
153
154        或由:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION_IN_BACKGROUND'], ......)
155        更改为:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION'], ......)
156
157    b) 当用户点击弹窗授予前台位置权限后,应用通过弹窗、提示窗等形式告知用户前往设置界面
158
159    c) 用户在设置界面选择【始终允许】选项,手动授予后台位置权限
160
1612、应用仅在requestPermissionsFromUser接口中申请后台位置权限
162
163    a) 排查应用是否需要后台位置权限,如需要,需要先弹窗申请前台位置权限(后台位置权限仅在前台位置权限生效情况下才能够使用)
164
165        由:atManager.requestPermissionsFromUser(context, ['ohos.permission.LOCATION_IN_BACKGROUND'], ......)
166        更改为:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION', 'ohos.permission.LOCATION'], ......)
167
168        或由:atManager.requestPermissionsFromUser(context, ['ohos.permission.LOCATION_IN_BACKGROUND'], ......)
169        更改为:atManager.requestPermissionsFromUser(context, ['ohos.permission.APPROXIMATELY_LOCATION'], ......)
170
171    b) 参考情况1
172
173接口使用的示例代码可参考[requestPermissionsFromUser接口指导](../../../application-dev/reference/apis/js-apis-abilityAccessCtrl.md#requestpermissionsfromuser9)
174