三星Galaxy S8 Android 7.0及更高版本阻止网络流量

时间:2018-07-09 16:56:55

标签: android android-networking android-8.0-oreo android-7.0-nougat samsung-galaxy

我正在开发针对运行 Oreo 牛轧糖的Samsung Galaxy S8的应用,该应用需要在后台持续访问网络。无论应用程序处于待机或打ze模式,该应用程序均需要按 ALL 时间定期发送UDP数据包并访问用户GPS位置。我知道这不是标准程序,但是此应用程序将不在Google Play商店中,并且此网络活动对于我们应用程序的功能至关重要。

出于开发目的,我引用此文档:

并通过使用startForegroundService和startForeground使我的应用程序与Oreo兼容,如以下视频所述:

我还添加了以下代码以选择退出电池优化:

    Intent intent = new Intent();
    String packageName = this.getPackageName();
    PowerManager pm = (PowerManager) this.getSystemService(Context.POWER_SERVICE);
    if (!pm.isIgnoringBatteryOptimizations(packageName)){
        intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
        intent.setData(Uri.parse("package:" + packageName));
        this.startActivity(intent);
    }

此外,我已关闭了所有电池优化和应用程序监视功能,并为我的应用程序选中了允许后台数据使用并在打开数据保护程序的同时允许应用程序。我还将Wi-Fi设置为“睡觉时允许”。如以下链接所述,我已经在使用ADB调试和测试应用程序待机/打ze时看到了正确的行为:

但是当我实际上拔出设备并继续运行应用程序时,我看不到模拟拔出和打do /待机时显示的行为。最终,对于在后台运行的应用程序,网络活动会停止,即使,前台服务通知仍显示发送UDP数据包的服务仍处于活动状态。这使调试变得非常困难,因为我无法像文档所建议的那样强制任何导致此adb的状态。这也使我怀疑这是三星的问题,而不是Android的问题,因为我认为我已尽我所能遵守Android后台执行标准。

当我发现网络中断后能够检查系统日志 时,仍然找不到任何问题的迹象,然后将电话插回去调试,可以确认我的服务流程仍然有效。这是logcat的一个片段,其中包含我的应用程序可以发送的最后一条UDP消息,然后不再发送它(在下面的跟踪中为07-09 12:10:17.206 23046-23107):

07-09 12:10:14.209 23046-23102/com.partyturtle.app.debug:service V/Mission: Got next location
07-09 12:10:14.347 3702-6311/? D/BatteryService: !@BatteryListener : batteryPropertiesChanged!
07-09 12:10:14.659 3702-4251/? D/libgps: OnGpsExtensionMessage: message_id(1), data(0x768b230044), size(2728)
07-09 12:10:14.659 3702-4251/? D/libgps: GpsiHook: API: gpsLocationCb(GpsiHookStateGps: e,c,G)
07-09 12:10:14.659 3702-4251/? D/libgps: proxy__gnss_sv_status_cb: called. num_svs(10)
07-09 12:10:14.660 3702-4251/? D/GnssLocationProvider_ex: SV Count : 10(7) / TOP5(v) : 23 21 19 19 15  / TOP5(u) : 23 21 19 19 15 
07-09 12:10:14.664 4240-4240/? D/DriftDetector_FLP: TCXO drift, list is full(2), Max = 435.0 / min = 435.0 / Drift = 0.0 / prevDrift = 435.0
07-09 12:10:14.665 3702-4339/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@643f1eb
07-09 12:10:14.667 3702-4339/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302195, nowELAPSED=1558254301
07-09 12:10:14.673 3702-3974/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121021 - CU:10028/CP:31419
07-09 12:10:14.673 3702-3974/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121021, SetElapsed=1558261297, nowELAPSED=1558254307
07-09 12:10:14.681 3702-4256/? I/LocationManagerService: remove a75c706
07-09 12:10:14.681 3702-4256/? I/LocationManagerService: removeUpdates, receiver.requestedID = a75c706
07-09 12:10:14.683 4240-4240/? E/RequestManager_FLP: [LocationManagerService] Location remove a75c706 from android
07-09 12:10:14.692 4240-4240/? D/BlacklistMonitor_FLP: checkProviderOperation, The size of providerList is larger than monitorList, mProvider = gps
07-09 12:10:14.693 4240-4240/? D/LocationManagerController_FLP: Already resume status so return
07-09 12:10:14.694 4240-4240/? D/BlacklistMonitor_FLP: checkProviderOperation, The size of providerList is larger than monitorList, mProvider = fused
07-09 12:10:14.694 4240-4240/? D/LocationManagerController_FLP: Already resume status so return
07-09 12:10:15.202 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next message tick
07-09 12:10:15.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye
07-09 12:10:15.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye sequence
07-09 12:10:15.206 23046-23107/com.partyturtle.app.debug:service D/Mission: **UDP message sent**
07-09 12:10:15.208 23046-23102/com.partyturtle.app.debug:service V/Mission: Got next location
07-09 12:10:15.660 4240-4240/? D/DriftDetector_FLP: TCXO drift, list is full(2), Max = 435.0 / min = 435.0 / Drift = 0.0 / prevDrift = 435.0
07-09 12:10:15.663 3702-4251/? D/libgps: OnGpsExtensionMessage: message_id(1), data(0x768b230044), size(2728)
07-09 12:10:15.663 3702-4251/? D/libgps: GpsiHook: API: gpsLocationCb(GpsiHookStateGps: e,c,G)
07-09 12:10:15.663 3702-4251/? D/libgps: proxy__gnss_sv_status_cb: called. num_svs(9)
07-09 12:10:15.664 3702-4251/? D/GnssLocationProvider_ex: SV Count : 9(7) / TOP5(v) : 23 21 20 19 15  / TOP5(u) : 23 21 20 19 15 
07-09 12:10:15.668 3702-4205/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@b6dc1c7
07-09 12:10:15.670 3702-4205/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558255304
07-09 12:10:15.674 3702-4256/? I/LocationManagerService: remove 5b053f4
07-09 12:10:15.674 3702-4256/? I/LocationManagerService: removeUpdates, receiver.requestedID = 5b053f4
07-09 12:10:15.680 4240-4240/? E/RequestManager_FLP: [LocationManagerService] Location remove 5b053f4 from android
07-09 12:10:15.681 3702-17869/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121022 - CU:10028/CP:31419
07-09 12:10:15.681 3702-17869/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121022, SetElapsed=1558262302, nowELAPSED=1558255315
07-09 12:10:15.687 4240-4240/? D/BlacklistMonitor_FLP: checkProviderOperation, The size of providerList is larger than monitorList, mProvider = gps
07-09 12:10:15.687 4240-4240/? D/LocationManagerController_FLP: Already resume status so return
07-09 12:10:15.687 4240-4240/? D/BlacklistMonitor_FLP: checkProviderOperation, The size of providerList is larger than monitorList, mProvider = fused
07-09 12:10:15.689 4240-4240/? D/LocationManagerController_FLP: Already resume status so return
07-09 12:10:15.830 4631-4631/? D/io_stats: !@   8,0 r 73156 4780028 w 484050 9282692 d 40893 3164864 f 180121 195116 iot 475556 265003 th 458260 0 0 pt 0 inp 0 0 159684.165
07-09 12:10:16.202 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next message tick
07-09 12:10:16.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye
07-09 12:10:16.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye sequence
07-09 12:10:16.206 23046-23107/com.partyturtle.app.debug:service D/Mission: **UDP message sent**
07-09 12:10:16.209 23046-23102/com.partyturtle.app.debug:service V/Mission: Got next location
07-09 12:10:16.658 4240-4240/? D/DriftDetector_FLP: TCXO drift, list is full(2), Max = 435.0 / min = 435.0 / Drift = 0.0 / prevDrift = 435.0
07-09 12:10:16.662 3702-4251/? D/libgps: OnGpsExtensionMessage: message_id(1), data(0x768b230044), size(2728)
07-09 12:10:16.662 3702-4251/? D/libgps: GpsiHook: API: gpsLocationCb(GpsiHookStateGps: e,c,G)
07-09 12:10:16.663 3702-4251/? D/libgps: proxy__gnss_sv_status_cb: called. num_svs(10)
07-09 12:10:16.663 3702-4251/? D/GnssLocationProvider_ex: SV Count : 10(7) / TOP5(v) : 23 21 20 19 15  / TOP5(u) : 23 21 20 19 15 
07-09 12:10:16.670 3702-5071/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@87ab363
07-09 12:10:16.672 3702-5071/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302195, nowELAPSED=1558256306
07-09 12:10:16.680 3702-20537/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121023 - CU:10028/CP:31419
07-09 12:10:16.680 3702-20537/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121023, SetElapsed=1558263300, nowELAPSED=1558256315
07-09 12:10:16.704 4879-4978/? D/ContactsProvider_EventLog: contents_sample_state: [ contacts(6) data(30) accounts({com.google (2)=6}) accounts deleted({}) calls([]) countryIso(US) userId(0)  ]
                                                            contents_sample_state: [ agr({[2]=6})  ]
                                                            contents_sample_state: [ actCnt({android.process.acore=1})  ]
07-09 12:10:16.707 4879-4978/? E/ContactsProvider_EventLog: Flush buffer to file cnt : 1 size : 0Kb duration : 2ms lastUpdatedAfter : 60107 ms mFlush_time_threasold : 2000 mCurrentSize : 279
07-09 12:10:17.202 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next message tick
07-09 12:10:17.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye
07-09 12:10:17.203 23046-23107/com.partyturtle.app.debug:service V/Mission: Got next bullseye sequence
07-09 12:10:17.206 23046-23107/com.partyturtle.app.debug:service D/Mission: **UDP message sent**
07-09 12:10:17.207 23046-23102/com.partyturtle.app.debug:service V/Mission: Got next location
07-09 12:10:17.655 3702-4251/? D/libgps: OnGpsExtensionMessage: message_id(1), data(0x768b230044), size(2728)
07-09 12:10:17.656 3702-4251/? D/libgps: GpsiHook: API: gpsLocationCb(GpsiHookStateGps: e,c,G)
07-09 12:10:17.656 3702-4251/? D/libgps: proxy__gnss_sv_status_cb: called. num_svs(9)
07-09 12:10:17.656 3702-4251/? D/GnssLocationProvider_ex: SV Count : 9(7) / TOP5(v) : 23 21 19 19 15  / TOP5(u) : 23 21 19 19 15 
07-09 12:10:17.659 4240-4240/? D/DriftDetector_FLP: TCXO drift, list is full(2), Max = 435.0 / min = 435.0 / Drift = 0.0 / prevDrift = 435.0
07-09 12:10:17.666 3702-6269/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@8d8b0de
07-09 12:10:17.668 3702-6269/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558257302
07-09 12:10:17.674 3702-4256/? I/LocationManagerService: remove 79e2d8c
07-09 12:10:17.674 3702-4256/? I/LocationManagerService: removeUpdates, receiver.requestedID = 79e2d8c
07-09 12:10:17.675 4240-4240/? E/RequestManager_FLP: [LocationManagerService] Location remove 79e2d8c from android
07-09 12:10:17.677 3702-5071/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121024 - CU:10028/CP:31419
07-09 12:10:17.680 3702-5071/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121024, SetElapsed=1558264293, nowELAPSED=1558257314
07-09 12:10:18.672 3702-15001/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@5bafcea
07-09 12:10:18.675 3702-15001/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302195, nowELAPSED=1558258309
07-09 12:10:18.683 3702-17869/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121025 - CU:10028/CP:31419
07-09 12:10:18.683 3702-17869/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121025, SetElapsed=1558265299, nowELAPSED=1558258317
07-09 12:10:19.666 3702-6269/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@4c3fdb6
07-09 12:10:19.668 3702-6269/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558259302
07-09 12:10:19.678 3702-4211/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121026 - CU:10028/CP:31419
07-09 12:10:19.679 3702-4211/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121026, SetElapsed=1558266296, nowELAPSED=1558259313
07-09 12:10:20.518 3702-5522/? D/SSRM:y: SIOP:: AP = 270, PST = 270 (W:15), CP = 266, CUR = -92, LCD = 0
07-09 12:10:20.529 3702-5522/? D/SSRM:c: ssrm_camera_info is null
07-09 12:10:20.550 3702-5522/? D/SSRM:b: ATC: power = AP = 84, LCD = -1, WIFI = 0, Camera = 0(Sensor:0, Comp:0), 
07-09 12:10:20.550 3702-5522/? D/SSRM:b: ATC: current = AP = 21, LCD = 56, WIFI = 0, Camera = 0(Sensor:0, Comp:0), 
07-09 12:10:20.551 3702-5522/? D/SSRM:b: ATC: Ambient Temperature = 26.00, Skin temperature = 26.00
07-09 12:10:20.668 3702-6311/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@5c6318d
07-09 12:10:20.671 3702-6311/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558260306
07-09 12:10:20.676 3702-17869/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121027 - CU:10028/CP:31419
07-09 12:10:20.676 3702-17869/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121027, SetElapsed=1558267301, nowELAPSED=1558260311
07-09 12:10:20.836 4631-4631/? D/io_stats: !@   8,0 r 73156 4780028 w 484061 9282820 d 40894 3164868 f 180123 195118 iot 475564 265007 th 458488 0 0 pt 0 inp 0 0 159689.171
07-09 12:10:21.666 3702-4205/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@a61bc90
07-09 12:10:21.668 3702-4205/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558261302
07-09 12:10:21.682 3702-4336/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121028 - CU:10028/CP:31419
07-09 12:10:21.683 3702-4336/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121028, SetElapsed=1558268304, nowELAPSED=1558261317
07-09 12:10:22.685 3702-9512/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@ece11bc
07-09 12:10:22.687 3702-9512/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302195, nowELAPSED=1558262321
07-09 12:10:22.695 3702-4044/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121029 - CU:10028/CP:31419
07-09 12:10:22.695 3702-4044/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121029, SetElapsed=1558269299, nowELAPSED=1558262329
07-09 12:10:23.668 3702-17869/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@c88c1cb
07-09 12:10:23.672 3702-17869/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558263306
07-09 12:10:23.677 3702-4348/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121030 - CU:10028/CP:31419
07-09 12:10:23.677 3702-4348/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121030, SetElapsed=1558270300, nowELAPSED=1558263311
07-09 12:10:24.671 3702-4211/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@85fafa7
07-09 12:10:24.673 3702-4211/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302195, nowELAPSED=1558264307
07-09 12:10:24.682 3702-31336/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121031 - CU:10028/CP:31419
07-09 12:10:24.682 3702-31336/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121031, SetElapsed=1558271303, nowELAPSED=1558264316
07-09 12:10:25.655 3702-4339/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@ccd9f43
07-09 12:10:25.657 3702-4339/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558265291
07-09 12:10:25.667 3702-4205/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121032 - CU:10028/CP:31419
07-09 12:10:25.667 3702-4205/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121032, SetElapsed=1558272288, nowELAPSED=1558265301
07-09 12:10:25.840 4631-4631/? D/io_stats: !@   8,0 r 73156 4780028 w 484073 9282924 d 40895 3164872 f 180124 195119 iot 475572 265010 th 458572 0 0 pt 0 inp 0 0 159694.176
07-09 12:10:26.669 3702-3796/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@911f63e
07-09 12:10:26.671 3702-3796/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558266305
07-09 12:10:26.676 3702-30541/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121033 - CU:10028/CP:31419
07-09 12:10:26.676 3702-30541/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121033, SetElapsed=1558273300, nowELAPSED=1558266311
07-09 12:10:27.673 3702-4839/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@dd2c9b5
07-09 12:10:27.674 3702-4839/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558267309
07-09 12:10:27.682 3702-4211/? D/SamsungAlarmManager: setExact Listener (T:3/F:1/AC:false) 20180709T121034 - CU:10028/CP:31419
07-09 12:10:27.683 3702-4211/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121034, SetElapsed=1558274303, nowELAPSED=1558267317
07-09 12:10:27.764 3702-4213/? E/Watchdog: !@Sync 5320 [09_Jul_12_10_27.764]
07-09 12:10:28.662 3702-14279/? D/SamsungAlarmManager: Cancel Alarm calling from uid:10028 pid :31419 / listener:android.app.IAlarmListener$Stub$Proxy@3b34c31
07-09 12:10:28.664 3702-14279/? I/SamsungAlarmManager: setLocked to kernel - T:3 / 20180709T121102, SetElapsed=1558302194, nowELAPSED=1558268299
07-09 12:10:28.674 3702-3974/? D/SamsungAlarmManager: setExact Listener

我的主要问题是:

  • 有没有一个原因,为什么我在使用ADB进行调试时测试休眠/待机时没有问题,但是拔出插头后却发现问题和行为发生了变化?
  • 此应用正常运行,并且所有具有 Nougat Nexus 5X 的后台网络活动均持续存在。如果该应用程序可以在Nexus 5X上正常运行,是否有理由无法在带有Nougat的S8上运行?
  • 是否在某些地方可以描述我所看到的行为的三星Galaxy S8应用管理的明确定义?也许“三星体验”实际上并没有杀死服务,但它确实起到了其他作用,例如只要需要就扼杀网络活动。如果是这种情况,那么我就不知道了。

感谢您抽出宝贵的时间阅读并提供任何帮助!如果我可以提供其他详细信息,请在评论中告诉我。

2 个答案:

答案 0 :(得分:0)

在“设置”中转到Device Maintainance,然后点击Battery, 如果您尚未将应用添加到“不受监视的应用”中,请添加它。


或者,点击3点菜单,然后关闭App Power monitor。 也许这会让您的应用进入休眠状态。

答案 1 :(得分:0)

我前一段时间在评论中发布了此帖子,最近的评论者提醒我,这个问题尚待解决,我认为我应该发布并接受对我有用的答案作为答案:

要解决我的问题,我最终不得不忽略电池优化, AND 将我的服务实现为前台服务, AND 确保CPU唤醒锁。