I am developing with the Pro version of the Radius Networks iBeacon SDK on a Samsung Galaxy Tab 2 running Android 4.3. The app has been successfully using the non-pro version 0.7 for a month now but I want the background events so I've gone to Pro version 1.0. The AndroidProximityLibrary project is a project dependency in Eclipse, and the ProximityKit.properties
file is in src/
.
The following code is my Application subclass, as described in the documentation. The app has BLUETOOTH and BLUETOOTH_ADMIN permissions. Notice from the LogCat output that the didDetermineStateForRegion()
method is not called after going to sleep as expected. What has to change to get something to happen in the background?
I have seen a similar question called iBeacon background scanning PRO feature of RadiusNetworks library? but the problem there seemed to be calling IBeaconManager.unbind()
which caused the OS to clean up the service. My code never calls IBeaconManager.unbind()
, only IBeaconManager.bind()
.
public class ExampleApp extends Application implements BootstrapNotifier, IBeaconConsumer {
private static final String LOG_TAG = ExampleApp.class.getName();
private RegionBootstrap regionBootstrap;
private IBeaconManager iBeacon;
private Region region;
public ExampleApp() {
String uuid = "EBEFD083-70A2-47C8-9837-E7B5634DF520";
region = new Region("com.example.ble", uuid, null, null);
}
@Override
public void onCreate() {
super.onCreate();
iBeacon = IBeaconManager.getInstanceForApplication(this);
iBeacon.setBackgroundBetweenScanPeriod(10000);
iBeacon.setBackgroundScanPeriod(3000);
iBeacon.bind(this);
regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void onIBeaconServiceConnect() {
Log.d(LOG_TAG + ".onIBeaconServiceConnect", "connected to iBeacon service");
try {
iBeacon.startRangingBeaconsInRegion(region);
} catch (RemoteException e) {
String msg = "caught exception while enabling beacon ranging";
Log.e(LOG_TAG + ".onIBeaconServiceConnect", msg, e);
}
}
@Override
public void didEnterRegion(Region region) {
Log.d(LOG_TAG + ".didEnterRegion", "YEAH ENTERED");
}
@Override
public void didDetermineStateForRegion(int state, Region region) {
Log.d(LOG_TAG + ".didDetermineStateForRegion", "YEAH STATE");
Intent intent = new Intent(this, LaunchActivity.class);
startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
@Override
public void didExitRegion(Region region) {
Log.d(LOG_TAG + ".didExitRegion", "YEAH EXITED");
}
}
I ran the app outside beacon range, then walked into range. After 30 seconds nothing had happened so I pressed the Power button and still nothing happened. I plugged the phone in and got the trace from ADB.
05-28 14:05:23.456: I/PowerManagerService(2392): [ps] Screen__Off(0) : goToSleepFromNative: (uid: 1000 pid: 2392)
05-28 14:05:23.456: I/PowerManagerService(2392): Going to sleep by user request...
05-28 14:05:23.471: W/KeyguardViewMediator(2392): wakeUpIfNeeded() mMaybeShow=true mRequestedWakeUp=false mShowing=false
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input11/enabled: No such file or directory
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input1/enabled: No such file or directory
05-28 14:05:23.516: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input10/enabled: No such file or directory
05-28 14:05:23.521: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_enable : 40
05-28 14:05:23.521: I/libsuspend(2392): !@[s] wait_for_fb_sleep : 40 (1, 0) -
05-28 14:05:23.521: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_enable done : 40
05-28 14:05:23.521: I/libsuspend(2392): !@[s] wait_for_fb_wake : 40 (0, 0) +
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] Off : 0s ago
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PowerManagerService.WakeLocks: ref count=1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PowerManagerService.Broadcasts: ref count=1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] mWakeLockSummary : 0x1
05-28 14:05:23.521: I/PowerManagerService(2392): [PWL] PARTIAL_WAKE_LOCK 'ActivityManager-Sleep' (uid=1000, pid=2392, ws=null) (elapsedTime=42)
05-28 14:05:23.526: I/CAE(2392): onReceive(CaPowerManager.java:142) - AP_SLEEP
05-28 14:05:23.531: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -46, 0,
05-28 14:05:23.561: I/CAE(2392): parse(SensorHubParserProvider.java:136) - buffer size = 3
05-28 14:05:23.561: I/CAE(2392): parse(SensorHubParserProvider.java:147) - 2, 1, -46,
05-28 14:05:23.591: I/AudioHardwareTinyALSA(1989): setParameters(screen_state=off)
05-28 14:05:23.591: I/audio_wfd_hw(1989): adev_set_parameters() screen_state=off
05-28 14:05:23.616: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.SCREEN_OFF)
05-28 14:05:23.621: E/NfcService(2909): callback == null
05-28 14:05:23.691: I/AutoBackupUtil(9627): checkAutoBackupCondition returns : false
05-28 14:05:23.691: I/AutoBackupUtil(9627): bChargerConnected : true
05-28 14:05:23.691: I/AutoBackupUtil(9627): bWifiConnected : false
05-28 14:05:23.691: I/AutoBackupUtil(9627): bScreenOn : false
05-28 14:05:24.871: I/SurfaceFlinger(1986): id=996 Removed Uoast (5/6)
05-28 14:05:24.871: I/SurfaceFlinger(1986): id=996 Removed Uoast (-2/6)
05-28 14:05:28.526: I/PowerManagerService(2392): [PWL] Off : 5s ago
05-28 14:05:38.541: I/PowerManagerService(2392): [PWL] Off : 15s ago
05-28 14:05:51.251: E/Watchdog(2392): !@Sync 8274
05-28 14:05:53.556: I/PowerManagerService(2392): [PWL] Off : 30s ago
05-28 14:05:55.986: E/BatteryService(2392): Could not open /efs/FactoryApp/batt_cable_count
05-28 14:05:56.081: E/Sensors(2392): Light old sensor_state 0, new sensor_state : 64 en : 1
05-28 14:05:56.096: I/SensorService(2392): info.selectDelay() ns=200000000
05-28 14:05:56.101: I/PowerManagerService(2392): [ps] Screen__On(wake lock) : wl: charger plug
05-28 14:05:56.101: I/PowerManagerService(2392): Waking up from sleep...
05-28 14:05:56.126: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_disable : 41
05-28 14:05:56.151: I/KeyguardBackgroundView(2392): *** KeyguardEffectView getInstance ***
05-28 14:05:56.151: I/WindowManager(2392): No lock screen!
05-28 14:05:56.196: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.USER_PRESENT)
05-28 14:05:56.266: E/videowall-TranscodeReceiver(10819): broadcastMSG : android.intent.action.ACTION_POWER_CONNECTED
05-28 14:05:56.276: I/EntropyMixer(2392): Writing entropy...
05-28 14:05:56.281: E/Sensors(2392): Light old sensor_state 64, new sensor_state : 0 en : 0
05-28 14:05:56.326: I/CAE(2392): onReceive(CaPowerManager.java:150) - POWER_CONNECTED
05-28 14:05:56.326: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -42, 0,
05-28 14:05:56.426: E/Launcher(2928): Error finding setting, default accessibility to not found: accessibility_enabled
05-28 14:05:56.536: I/SSRMv2:Monitor(2392): fileWriteInt : /sys/class/power_supply/battery/siop_level value : 100
05-28 14:05:56.546: E/Sensors(2392): Light old sensor_state 0, new sensor_state : 64 en : 1
05-28 14:05:56.556: I/SensorService(2392): info.selectDelay() ns=200000000
05-28 14:05:56.556: E/Sensors(2392): Light old sensor_state 64, new sensor_state : 0 en : 0
05-28 14:05:56.556: E/MotionRecognitionService(2392): mReceiver.onReceive : ACTION_USER_PRESENT :: UNLOCK SCREEN
05-28 14:05:56.571: E/BatteryService(2392): Could not open /efs/FactoryApp/batt_cable_count
05-28 14:05:56.576: I/libsuspend(2392): !@[s] wait_for_fb_wake : 41 (1, 0) -
05-28 14:05:56.576: I/libsuspend(2392): !@[s] wait_for_fb_sleep : 41 (0, 0) +
05-28 14:05:56.576: I/libsuspend(2392): !@[s] autosuspend_earlysuspend_disable done : 41
05-28 14:05:56.576: E/SecTVOutService(1986): virtual void android::SecTVOutService::setHdmiStatus(uint32_t)::mSecHdmi.connect() fail
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input11/enabled: No such file or directory
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input1/enabled: No such file or directory
05-28 14:05:56.576: E/SEC PowerHAL(2392): sysfs_write : Error opening /sys/class/input/input10/enabled: No such file or directory
05-28 14:05:56.616: I/CAE(2392): onReceive(CaPowerManager.java:146) - AP_WAKEUP
05-28 14:05:56.616: I/CAE(2392): sendCmdToSensorHub(SensorHubCommManager.java:146) - -76, 13, -47, 0,
05-28 14:05:56.681: I/AudioHardwareTinyALSA(1989): setParameters(screen_state=on)
05-28 14:05:56.681: I/audio_wfd_hw(1989): adev_set_parameters() screen_state=on
05-28 14:05:56.796: E/SELinux(11287): Function: selinux_android_load_priority [0], There is no sepolicy file
05-28 14:05:56.796: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287): Function: selinux_android_load_priority , loading version is VE=SEPF_GT-N7105_4.3_0021
05-28 14:05:56.801: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287):
05-28 14:05:56.801: E/SELinux(11287): selinux_android_seapp_context_reload: seapp_contexts file is loaded from /data/security/spota/seapp_contexts
05-28 14:05:56.821: I/NfcService(2909): NFC: When Screen On, S View Cover also Open!!
05-28 14:05:56.821: I/NfcService(2909): # NativeNfcBrcmPowerMode; setPowerMode(android.intent.action.SCREEN_ON)
05-28 14:05:56.841: I/CAE(2392): parse(SensorHubParserProvider.java:136) - buffer size = 3
05-28 14:05:56.841: I/CAE(2392): parse(SensorHubParserProvider.java:147) - 2, 1, -47,
05-28 14:05:56.871: I/ActivityManager(2392): Killing proc 11287:com.sec.android.SimpleWidget/u0a10145: force stop com.sec.android.SimpleWidget
05-28 14:05:56.886: W/ActivityManager(2392): Permission denied: checkComponentPermission() owningUid=10029
The solution is to call IBeaconManager.updateScanPeriods()
after setBackgroundBetweenScanPeriod()
or setBackgroundScanPeriod()
is called. Since my code didn't do that, the Radius SDK was still scanning at default intervals (10 minutes in the background).