|
23 | 23 | package com.tencent.qcloud.track; |
24 | 24 |
|
25 | 25 | import android.content.Context; |
| 26 | +import android.content.SharedPreferences; |
26 | 27 | import android.content.pm.PackageInfo; |
27 | 28 | import android.content.pm.PackageManager; |
28 | 29 | import android.os.Build; |
| 30 | +import android.provider.Settings; |
29 | 31 | import android.util.Log; |
30 | 32 |
|
31 | 33 | import com.tencent.beacon.event.open.BeaconConfig; |
|
34 | 36 | import com.tencent.qcloud.track.service.BeaconTrackService; |
35 | 37 | import com.tencent.qcloud.track.service.ClsTrackService; |
36 | 38 | import com.tencent.qcloud.track.utils.NetworkUtils; |
37 | | -import com.tencent.qimei.sdk.IQimeiSDK; |
38 | | -import com.tencent.qimei.sdk.QimeiSDK; |
39 | 39 |
|
40 | 40 | import java.util.ArrayList; |
41 | 41 | import java.util.HashMap; |
42 | 42 | import java.util.List; |
43 | 43 | import java.util.Map; |
| 44 | +import java.util.UUID; |
44 | 45 |
|
45 | 46 | /** |
46 | 47 | * 数据追踪服务 |
@@ -92,9 +93,9 @@ public synchronized void init(Context context) { |
92 | 93 | if (!isInitialized) { |
93 | 94 | this.context = context.getApplicationContext(); |
94 | 95 | commonParams = getCommonParams(); |
95 | | - // 因为默认上报简单数据到灯塔,因此默认初始化灯塔和QIMEI |
| 96 | + // 因为默认上报简单数据到灯塔,因此默认初始化灯塔 |
96 | 97 | if (BeaconTrackService.isInclude()) { |
97 | | - initBeaconAndQimei(); |
| 98 | + initBeacon(); |
98 | 99 | simpleDataTrackService = new BeaconTrackService(); |
99 | 100 | // 设置context |
100 | 101 | simpleDataTrackService.setContext(context); |
@@ -230,36 +231,28 @@ public void setDebug(boolean debug) { |
230 | 231 | } |
231 | 232 |
|
232 | 233 | /** |
233 | | - * 初始化灯塔和qimei |
| 234 | + * 初始化灯塔 |
234 | 235 | */ |
235 | | - private void initBeaconAndQimei() { |
| 236 | + private void initBeacon() { |
236 | 237 | BeaconConfig.Builder builder = BeaconConfig.builder() |
237 | 238 | .auditEnable(false) |
238 | 239 | .bidEnable(false) |
239 | 240 | .qmspEnable(false) |
240 | 241 | .pagePathEnable(false) |
241 | | -// .setNeedInitQimei(false) |
242 | 242 | .setNormalPollingTime(30000); |
243 | 243 | BeaconConfig config = builder.build(); |
244 | | - |
245 | 244 | BeaconReport beaconReport = BeaconReport.getInstance(); |
246 | 245 | try { |
247 | 246 | beaconReport.setCollectProcessInfo(false); //该项设为false即关闭采集processInfo功能 |
248 | 247 | } catch (NoSuchMethodError error) { |
249 | 248 | } |
| 249 | + |
250 | 250 | // 多次初始化,或者初始化时传入的appkey和manifest.xml文件内不同,debug模式 |
251 | 251 | // 下会主动抛出异常 |
252 | 252 | try { |
253 | | - IQimeiSDK qimeiSDK = QimeiSDK.getInstance(Constants.SIMPLE_DATA_BEACON_APP_KEY); |
254 | | - qimeiSDK.getStrategy() |
255 | | - .enableOAID(false) // 关闭oaid采集,这里设置false |
256 | | - .enableIMEI(false) // 关闭imei采集,这里设置false,建议如用户授权,尽可能采集,便于复核问题 |
257 | | - .enableIMSI(false) // 关闭imsi采集,这里设置false |
258 | | - .enableAndroidId(false) // 关闭android id采集,这里设置false,建议如用户授权,尽可能采集,便于复核问题 |
259 | | - .enableMAC(false) // 关闭mac采集,这里设置false |
260 | | - .enableCid(false) // 关闭cid采集,这里设置false |
261 | | - .enableProcessInfo(false) // 关闭应用列表枚举,这里设置false,1.0.5以上版本有效 |
262 | | - .enableBuildModel(false); // 关闭BUILD.MODEL采集,这里设置false,1.2.3以上版本有效 |
| 253 | + String deviceId = getSafeDeviceId(); |
| 254 | +// Log.d(TAG, "ostar_deviceId: " + deviceId); |
| 255 | + beaconReport.setOstar(deviceId, deviceId); //必须,但可以在初始化之后设置,灯塔会缓存ostar为空的事件set之后重报 |
263 | 256 |
|
264 | 257 | beaconReport.start(context, Constants.SIMPLE_DATA_BEACON_APP_KEY, config); |
265 | 258 | } catch (Exception e) { |
@@ -304,4 +297,33 @@ private Map<String, String> getCommonParams() { |
304 | 297 |
|
305 | 298 | return params; |
306 | 299 | } |
| 300 | + |
| 301 | + /** |
| 302 | + * 获取安全设备标识(自动生成并缓存) |
| 303 | + */ |
| 304 | + public String getSafeDeviceId() { |
| 305 | + SharedPreferences prefs = context.getSharedPreferences("cossdk_device_info", Context.MODE_PRIVATE); |
| 306 | + String storedId = prefs.getString("device_id", null); |
| 307 | + if (storedId != null) { |
| 308 | + return storedId; |
| 309 | + } |
| 310 | + String newId = createNewId(); |
| 311 | + prefs.edit().putString("device_id", newId).apply(); |
| 312 | + return newId; |
| 313 | + } |
| 314 | + |
| 315 | + /** |
| 316 | + * 生成新标识的私有方法 |
| 317 | + */ |
| 318 | + private String createNewId() { |
| 319 | + String androidId = Settings.Secure.getString( |
| 320 | + context.getContentResolver(), |
| 321 | + Settings.Secure.ANDROID_ID |
| 322 | + ); |
| 323 | + if (androidId != null && !androidId.isEmpty()) { |
| 324 | + return androidId; |
| 325 | + } else { |
| 326 | + return UUID.randomUUID().toString(); |
| 327 | + } |
| 328 | + } |
307 | 329 | } |
0 commit comments