正在查看: Meine NEW v2.0.3616 应用的 BeaconManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Meine NEW v2.0.3616 应用的 BeaconManager.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package org.altbeacon.beacon;
import android.annotation.TargetApi;
import android.app.Notification;
import android.bluetooth.BluetoothManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.ResolveInfo;
import android.os.Build;
import android.os.IBinder;
import android.os.Message;
import android.os.Messenger;
import android.os.RemoteException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
import l0.n;
import org.altbeacon.beacon.logging.LogManager;
import org.altbeacon.beacon.logging.Loggers;
import org.altbeacon.beacon.powersave.BackgroundPowerSaverInternal;
import org.altbeacon.beacon.service.BeaconService;
import org.altbeacon.beacon.service.Callback;
import org.altbeacon.beacon.service.IntentScanStrategyCoordinator;
import org.altbeacon.beacon.service.MonitoringStatus;
import org.altbeacon.beacon.service.RangeState;
import org.altbeacon.beacon.service.RangedBeacon;
import org.altbeacon.beacon.service.RegionMonitoringState;
import org.altbeacon.beacon.service.RunningAverageRssiFilter;
import org.altbeacon.beacon.service.ScanJobScheduler;
import org.altbeacon.beacon.service.SettingsData;
import org.altbeacon.beacon.service.StartRMData;
import org.altbeacon.beacon.service.scanner.NonBeaconLeScanCallback;
import org.altbeacon.beacon.simulator.BeaconSimulator;
import org.altbeacon.beacon.utils.ProcessUtils;
public class BeaconManager {
public static final long DEFAULT_BACKGROUND_BETWEEN_SCAN_PERIOD = 300000;
public static final long DEFAULT_BACKGROUND_SCAN_PERIOD = 10000;
public static final long DEFAULT_EXIT_PERIOD = 10000;
public static final long DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD = 0;
public static final long DEFAULT_FOREGROUND_SCAN_PERIOD = 1100;
private static final String TAG = "BeaconManager";
protected static BeaconSimulator beaconSimulator = null;
protected static String distanceModelUpdateUrl = "https://s3.amazonaws.com/android-beacon-library/android-distance.json";
private static boolean sAndroidLScanningDisabled = false;
private static long sExitRegionPeriod = 10000;
protected static volatile BeaconManager sInstance = null;
private static boolean sManifestCheckingDisabled = false;
private BeaconConsumer autoBindConsumer;
private long backgroundBetweenScanPeriod;
private long backgroundScanPeriod;
private final List<BeaconParser> beaconParsers;
private long foregroundBetweenScanPeriod;
private long foregroundScanPeriod;
private boolean mBackgroundMode;
private boolean mBackgroundModeUninitialized;
private final Context mContext;
private Notification mForegroundServiceNotification;
private int mForegroundServiceNotificationId;
private IntentScanStrategyCoordinator mIntentScanStrategyCoordinator;
BackgroundPowerSaverInternal mInternalBackgroundPowerSaver;
private boolean mMainProcess;
private NonBeaconLeScanCallback mNonBeaconLeScanCallback;
private boolean mRegionStatePersistenceEnabled;
private HashMap<Region, RegionViewModel> mRegionViewModels;
private Boolean mScannerInSameProcess;
private boolean mScheduledScanJobsEnabled;
private static final Object SINGLETON_LOCK = new Object();
protected static Class rssiFilterImplClass = RunningAverageRssiFilter.class;
private final ConcurrentMap<InternalBeaconConsumer, ConsumerInfo> consumers = new ConcurrentHashMap();
private Messenger serviceMessenger = null;
protected final Set<RangeNotifier> rangeNotifiers = new CopyOnWriteArraySet();
protected RangeNotifier dataRequestNotifier = null;
protected final Set<MonitorNotifier> monitorNotifiers = new CopyOnWriteArraySet();
private final Set<Region> rangedRegions = new CopyOnWriteArraySet();
private final Set<Region> autoBindRangedRegions = new HashSet();
private final Set<Region> autoBindMonitoredRegions = new HashSet();
public class BeaconServiceConnection implements ServiceConnection {
@Override
public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
LogManager.d(BeaconManager.TAG, "we have a connection to the service now", new Object[0]);
if (BeaconManager.this.mScannerInSameProcess == null) {
BeaconManager.this.mScannerInSameProcess = Boolean.FALSE;
}
BeaconManager.this.serviceMessenger = new Messenger(iBinder);
BeaconManager.this.applySettings();
synchronized (BeaconManager.this.consumers) {
for (Map.Entry entry : BeaconManager.this.consumers.entrySet()) {
if (!((ConsumerInfo) entry.getValue()).isConnected) {
((InternalBeaconConsumer) entry.getKey()).onBeaconServiceConnect();
((ConsumerInfo) entry.getValue()).isConnected = true;
}
}
}
}
@Override
public void onServiceDisconnected(ComponentName componentName) {
LogManager.e(BeaconManager.TAG, "onServiceDisconnected", new Object[0]);
BeaconManager.this.serviceMessenger = null;
}
private BeaconServiceConnection() {
}
}
public class ConsumerInfo {
public BeaconServiceConnection beaconServiceConnection;
public boolean isConnected = false;
public ConsumerInfo() {
this.beaconServiceConnection = new BeaconServiceConnection();
}
}
public class ServiceNotDeclaredException extends RuntimeException {
public ServiceNotDeclaredException() {
super("The BeaconService is not properly declared in AndroidManifest.xml. If using Eclipse, please verify that your project.properties has manifestmerger.enabled=true");
}
}
public BeaconManager(Context context) {
CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();
this.beaconParsers = copyOnWriteArrayList;
this.mRegionStatePersistenceEnabled = true;
this.mBackgroundMode = false;
this.mBackgroundModeUninitialized = true;
this.mMainProcess = false;
this.mScannerInSameProcess = null;
this.mScheduledScanJobsEnabled = false;
this.mIntentScanStrategyCoordinator = null;
this.mForegroundServiceNotification = null;
this.mForegroundServiceNotificationId = -1;
this.foregroundScanPeriod = DEFAULT_FOREGROUND_SCAN_PERIOD;
this.foregroundBetweenScanPeriod = 0L;
this.backgroundScanPeriod = 10000L;
this.backgroundBetweenScanPeriod = DEFAULT_BACKGROUND_BETWEEN_SCAN_PERIOD;
this.mRegionViewModels = new HashMap<>();
this.autoBindConsumer = null;
this.mInternalBackgroundPowerSaver = null;
this.mContext = context.getApplicationContext();
checkIfMainProcess();
if (!sManifestCheckingDisabled) {
verifyServiceDeclaration();
}
copyOnWriteArrayList.add(new AltBeaconParser());
setScheduledScanJobsEnabledDefault();
}
@TargetApi(18)
private void applyChangesToServices(int i, Region region) {
if (!isAnyConsumerBound()) {
LogManager.w(TAG, "The BeaconManager is not bound to the service. Call beaconManager.bind(BeaconConsumer consumer) and wait for a callback to onBeaconServiceConnect()", new Object[0]);
return;
}
IntentScanStrategyCoordinator intentScanStrategyCoordinator = this.mIntentScanStrategyCoordinator;
if (intentScanStrategyCoordinator != null) {
intentScanStrategyCoordinator.applySettings();
return;
}
if (this.mScheduledScanJobsEnabled) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(this.mContext, this);
return;
}
Message obtain = Message.obtain(null, i, 0, 0);
if (i == 6) {
obtain.setData(new StartRMData(getScanPeriod(), getBetweenScanPeriod(), this.mBackgroundMode).toBundle());
} else if (i == 7) {
obtain.setData(new SettingsData().collect(this.mContext).toBundle());
} else {
obtain.setData(new StartRMData(region, callbackPackageName(), getScanPeriod(), getBetweenScanPeriod(), this.mBackgroundMode).toBundle());
}
this.serviceMessenger.send(obtain);
}
private synchronized void autoBind() {
if (this.autoBindConsumer == null) {
this.autoBindConsumer = new BeaconConsumer() {
@Override
public boolean bindService(Intent intent, ServiceConnection serviceConnection, int i) {
return BeaconManager.this.mContext.bindService(intent, serviceConnection, i);
}
@Override
public Context getApplicationContext() {
return BeaconManager.this.mContext;
}
@Override
public void onBeaconServiceConnect() {
if (!BeaconManager.this.isBleAvailableOrSimulated()) {
LogManager.w(BeaconManager.TAG, "Method invocation will be ignored -- no BLE.", new Object[0]);
return;
}
synchronized (BeaconManager.this.autoBindRangedRegions) {
Iterator it = BeaconManager.this.autoBindRangedRegions.iterator();
while (it.hasNext()) {
try {
BeaconManager.this.startRangingBeaconsInRegion((Region) it.next());
} catch (RemoteException e) {
LogManager.e(BeaconManager.TAG, "Failed to start ranging", e);
}
}
BeaconManager.this.autoBindRangedRegions.clear();
}
synchronized (BeaconManager.this.autoBindMonitoredRegions) {
Iterator it2 = BeaconManager.this.autoBindMonitoredRegions.iterator();
while (it2.hasNext()) {
try {
BeaconManager.this.startMonitoringBeaconsInRegion((Region) it2.next());
} catch (RemoteException e2) {
LogManager.e(BeaconManager.TAG, "Failed to start monitoring", e2);
}
}
BeaconManager.this.autoBindMonitoredRegions.clear();
}
}
@Override
public void unbindService(ServiceConnection serviceConnection) {
BeaconManager.this.mContext.unbindService(serviceConnection);
}
};
}
bindInternal(this.autoBindConsumer);
}
private void autoUnbindIfNeeded() {
BeaconConsumer beaconConsumer;
if (getMonitoredRegions().size() == 0 && getRangedRegions().size() == 0 && (beaconConsumer = this.autoBindConsumer) != null) {
unbindInternal(beaconConsumer);
this.autoBindConsumer = null;
this.autoBindRangedRegions.clear();
this.autoBindMonitoredRegions.clear();
}
}
private String callbackPackageName() {
String packageName = this.mContext.getPackageName();
LogManager.d(TAG, "callback packageName: %s", packageName);
return packageName;
}
private boolean determineIfCalledFromSeparateScannerProcess() {
if (!isScannerInDifferentProcess() || isMainProcess()) {
return false;
}
LogManager.w(TAG, "Ranging/Monitoring may not be controlled from a separate BeaconScanner process. To remove this warning, please wrap this call in: if (beaconManager.isMainProcess())", new Object[0]);
return true;
}
private void ensureBackgroundPowerSaver() {
if (this.mInternalBackgroundPowerSaver == null) {
BackgroundPowerSaverInternal backgroundPowerSaverInternal = new BackgroundPowerSaverInternal(this.mContext);
this.mInternalBackgroundPowerSaver = backgroundPowerSaverInternal;
backgroundPowerSaverInternal.enableDefaultBackgroundStateInference();
}
}
public static BeaconSimulator getBeaconSimulator() {
return beaconSimulator;
}
private long getBetweenScanPeriod() {
return this.mBackgroundMode ? this.backgroundBetweenScanPeriod : this.foregroundBetweenScanPeriod;
}
public static String getDistanceModelUpdateUrl() {
return distanceModelUpdateUrl;
}
public static BeaconManager getInstanceForApplication(Context context) {
BeaconManager beaconManager = sInstance;
if (beaconManager == null) {
synchronized (SINGLETON_LOCK) {
beaconManager = sInstance;
if (beaconManager == null) {
beaconManager = new BeaconManager(context);
sInstance = beaconManager;
}
}
}
return beaconManager;
}
public static boolean getManifestCheckingDisabled() {
return sManifestCheckingDisabled;
}
public static long getRegionExitPeriod() {
return sExitRegionPeriod;
}
public static Class getRssiFilterImplClass() {
return rssiFilterImplClass;
}
private long getScanPeriod() {
return this.mBackgroundMode ? this.backgroundScanPeriod : this.foregroundScanPeriod;
}
public static boolean isAndroidLScanningDisabled() {
return sAndroidLScanningDisabled;
}
private boolean isBleAvailable() {
if (this.mContext.getPackageManager().hasSystemFeature("android.hardware.bluetooth_le")) {
return true;
}
LogManager.w(TAG, "This device does not support bluetooth LE.", new Object[0]);
return false;
}
public boolean isBleAvailableOrSimulated() {
if (getBeaconSimulator() != null) {
return true;
}
return isBleAvailable();
}
@Deprecated
public static void logDebug(String str, String str2) {
LogManager.d(str, str2, new Object[0]);
}
public static void setAndroidLScanningDisabled(boolean z) {
sAndroidLScanningDisabled = z;
BeaconManager beaconManager = sInstance;
if (beaconManager != null) {
beaconManager.applySettings();
}
}
public static void setBeaconSimulator(BeaconSimulator beaconSimulator2) {
warnIfScannerNotInSameProcess();
beaconSimulator = beaconSimulator2;
}
public static void setDebug(boolean z) {
if (z) {
LogManager.setLogger(Loggers.verboseLogger());
LogManager.setVerboseLoggingEnabled(true);
} else {
LogManager.setLogger(Loggers.empty());
LogManager.setVerboseLoggingEnabled(false);
}
}
public static void setDistanceModelUpdateUrl(String str) {
warnIfScannerNotInSameProcess();
distanceModelUpdateUrl = str;
}
public static void setManifestCheckingDisabled(boolean z) {
sManifestCheckingDisabled = z;
}
public static void setRegionExitPeriod(long j) {
sExitRegionPeriod = j;
BeaconManager beaconManager = sInstance;
if (beaconManager != null) {
beaconManager.applySettings();
}
}
public static void setRssiFilterImplClass(Class cls) {
warnIfScannerNotInSameProcess();
rssiFilterImplClass = cls;
}
private void setScheduledScanJobsEnabledDefault() {
this.mScheduledScanJobsEnabled = Build.VERSION.SDK_INT >= 26;
}
public static void setUseTrackingCache(boolean z) {
RangeState.setUseTrackingCache(z);
if (sInstance != null) {
sInstance.applySettings();
}
}
@Deprecated
public static void setsManifestCheckingDisabled(boolean z) {
sManifestCheckingDisabled = z;
}
private void verifyServiceDeclaration() {
List<ResolveInfo> queryIntentServices = this.mContext.getPackageManager().queryIntentServices(new Intent(this.mContext, (Class<?>) BeaconService.class), 65536);
if (queryIntentServices != null && queryIntentServices.isEmpty()) {
throw new ServiceNotDeclaredException();
}
}
private static void warnIfScannerNotInSameProcess() {
BeaconManager beaconManager = sInstance;
if (beaconManager == null || !beaconManager.isScannerInDifferentProcess()) {
return;
}
LogManager.w(TAG, "Unsupported configuration change made for BeaconScanner in separate process", new Object[0]);
}
public void addMonitorNotifier(MonitorNotifier monitorNotifier) {
if (determineIfCalledFromSeparateScannerProcess() || monitorNotifier == null) {
return;
}
this.monitorNotifiers.add(monitorNotifier);
}
public void addRangeNotifier(RangeNotifier rangeNotifier) {
if (rangeNotifier != null) {
this.rangeNotifiers.add(rangeNotifier);
}
}
public void applySettings() {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
if (!isAnyConsumerBound()) {
LogManager.d(TAG, "Not synchronizing settings to service, as it has not started up yet", new Object[0]);
} else if (!isScannerInDifferentProcess()) {
LogManager.d(TAG, "Not synchronizing settings to service, as it is in the same process", new Object[0]);
} else {
LogManager.d(TAG, "Synchronizing settings to service", new Object[0]);
syncSettingsToService();
}
}
@Deprecated
public void bind(BeaconConsumer beaconConsumer) {
bindInternal(beaconConsumer);
}
public void bindInternal(InternalBeaconConsumer internalBeaconConsumer) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
synchronized (this.consumers) {
ConsumerInfo consumerInfo = new ConsumerInfo();
if (this.consumers.putIfAbsent(internalBeaconConsumer, consumerInfo) != null) {
LogManager.d(TAG, "This consumer is already bound", new Object[0]);
} else {
LogManager.d(TAG, "This consumer is not bound. Binding now: %s", internalBeaconConsumer);
IntentScanStrategyCoordinator intentScanStrategyCoordinator = this.mIntentScanStrategyCoordinator;
if (intentScanStrategyCoordinator != null) {
intentScanStrategyCoordinator.start();
internalBeaconConsumer.onBeaconServiceConnect();
} else if (this.mScheduledScanJobsEnabled) {
LogManager.d(TAG, "Not starting beacon scanning service. Using scheduled jobs", new Object[0]);
internalBeaconConsumer.onBeaconServiceConnect();
} else {
LogManager.d(TAG, "Binding to service", new Object[0]);
Intent intent = new Intent(internalBeaconConsumer.getApplicationContext(), (Class<?>) BeaconService.class);
if (Build.VERSION.SDK_INT >= 26 && getForegroundServiceNotification() != null) {
if (isAnyConsumerBound()) {
LogManager.i(TAG, "Not starting foreground beacon scanning service. A consumer is already bound, so it should be started", new Object[0]);
} else {
LogManager.i(TAG, "Starting foreground beacon scanning service.", new Object[0]);
n.l(this.mContext, intent);
}
}
internalBeaconConsumer.bindService(intent, consumerInfo.beaconServiceConnection, 1);
}
LogManager.d(TAG, "consumer count is now: %s", Integer.valueOf(this.consumers.size()));
}
}
}
@TargetApi(18)
public boolean checkAvailability() {
if (isBleAvailableOrSimulated()) {
return ((BluetoothManager) this.mContext.getSystemService("bluetooth")).getAdapter().isEnabled();
}
throw new BleNotAvailableException("Bluetooth LE not supported by this device");
}
public void checkIfMainProcess() {
ProcessUtils processUtils = new ProcessUtils(this.mContext);
String processName = processUtils.getProcessName();
String packageName = processUtils.getPackageName();
int pid = processUtils.getPid();
this.mMainProcess = processUtils.isMainProcess();
LogManager.i(TAG, "BeaconManager started up on pid " + pid + " named '" + processName + "' for application package '" + packageName + "'. isMainProcess=" + this.mMainProcess, new Object[0]);
}
public void disableForegroundServiceScanning() {
if (isAnyConsumerBound()) {
throw new IllegalStateException("May not be called after consumers are already bound");
}
this.mForegroundServiceNotification = null;
setScheduledScanJobsEnabledDefault();
}
public void enableForegroundServiceScanning(Notification notification, int i) {
if (isAnyConsumerBound()) {
throw new IllegalStateException("May not be called after consumers are already bound.");
}
if (notification == null) {
throw new NullPointerException("Notification cannot be null");
}
setEnableScheduledScanJobs(false);
this.mForegroundServiceNotification = notification;
this.mForegroundServiceNotificationId = i;
}
public long getBackgroundBetweenScanPeriod() {
return this.backgroundBetweenScanPeriod;
}
public boolean getBackgroundMode() {
return this.mBackgroundMode;
}
public long getBackgroundScanPeriod() {
return this.backgroundScanPeriod;
}
public List<BeaconParser> getBeaconParsers() {
return this.beaconParsers;
}
public RangeNotifier getDataRequestNotifier() {
return this.dataRequestNotifier;
}
public long getForegroundBetweenScanPeriod() {
return this.foregroundBetweenScanPeriod;
}
public long getForegroundScanPeriod() {
return this.foregroundScanPeriod;
}
public Notification getForegroundServiceNotification() {
return this.mForegroundServiceNotification;
}
public int getForegroundServiceNotificationId() {
return this.mForegroundServiceNotificationId;
}
public IntentScanStrategyCoordinator getIntentScanStrategyCoordinator() {
return this.mIntentScanStrategyCoordinator;
}
public Collection<Region> getMonitoredRegions() {
return MonitoringStatus.getInstanceForApplication(this.mContext).regions();
}
@Deprecated
public MonitorNotifier getMonitoringNotifier() {
Iterator<MonitorNotifier> it = this.monitorNotifiers.iterator();
if (it.hasNext()) {
return it.next();
}
return null;
}
public Set<MonitorNotifier> getMonitoringNotifiers() {
return Collections.unmodifiableSet(this.monitorNotifiers);
}
public NonBeaconLeScanCallback getNonBeaconLeScanCallback() {
return this.mNonBeaconLeScanCallback;
}
public Collection<Region> getRangedRegions() {
return Collections.unmodifiableSet(this.rangedRegions);
}
@Deprecated
public RangeNotifier getRangingNotifier() {
Iterator<RangeNotifier> it = this.rangeNotifiers.iterator();
if (it.hasNext()) {
return it.next();
}
return null;
}
public Set<RangeNotifier> getRangingNotifiers() {
return Collections.unmodifiableSet(this.rangeNotifiers);
}
public RegionViewModel getRegionViewModel(Region region) {
RegionViewModel regionViewModel = this.mRegionViewModels.get(region);
if (regionViewModel != null) {
return regionViewModel;
}
RegionViewModel regionViewModel2 = new RegionViewModel();
this.mRegionViewModels.put(region, regionViewModel2);
return regionViewModel2;
}
public boolean getScheduledScanJobsEnabled() {
return this.mScheduledScanJobsEnabled;
}
public void handleStategyFailover() {
IntentScanStrategyCoordinator intentScanStrategyCoordinator = this.mIntentScanStrategyCoordinator;
if (intentScanStrategyCoordinator == null || !intentScanStrategyCoordinator.getDisableOnFailure() || this.mIntentScanStrategyCoordinator.getLastStrategyFailureDetectionCount() <= 0) {
return;
}
this.mIntentScanStrategyCoordinator = null;
LogManager.d(TAG, "unbinding all consumers for failover from intent strategy", new Object[0]);
ArrayList arrayList = new ArrayList(this.consumers.keySet());
Iterator it = arrayList.iterator();
while (it.hasNext()) {
unbindInternal((InternalBeaconConsumer) it.next());
}
LogManager.d(TAG, "binding all consumers for failover from intent strategy", new Object[0]);
Iterator it2 = arrayList.iterator();
while (it2.hasNext()) {
bindInternal((InternalBeaconConsumer) it2.next());
}
LogManager.d(TAG, "Done with failover", new Object[0]);
}
public boolean isAnyConsumerBound() {
boolean z;
synchronized (this.consumers) {
z = (this.consumers.isEmpty() || (this.mIntentScanStrategyCoordinator == null && !this.mScheduledScanJobsEnabled && this.serviceMessenger == null)) ? false : true;
}
return z;
}
public boolean isAutoBindActive() {
return this.autoBindConsumer != null;
}
public boolean isBackgroundModeUninitialized() {
return this.mBackgroundModeUninitialized;
}
@Deprecated
public boolean isBound(BeaconConsumer beaconConsumer) {
boolean z;
synchronized (this.consumers) {
if (beaconConsumer != null) {
try {
z = this.consumers.get(beaconConsumer) != null && (this.mScheduledScanJobsEnabled || this.serviceMessenger != null);
} finally {
}
}
}
return z;
}
public boolean isMainProcess() {
return this.mMainProcess;
}
public boolean isRegionStatePersistenceEnabled() {
return this.mRegionStatePersistenceEnabled;
}
public boolean isRegionViewModelInitialized(Region region) {
return this.mRegionViewModels.get(region) != null;
}
public boolean isScannerInDifferentProcess() {
Boolean bool = this.mScannerInSameProcess;
return (bool == null || bool.booleanValue()) ? false : true;
}
public void removeAllMonitorNotifiers() {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
this.monitorNotifiers.clear();
}
public void removeAllRangeNotifiers() {
this.rangeNotifiers.clear();
}
public boolean removeMonitorNotifier(MonitorNotifier monitorNotifier) {
if (determineIfCalledFromSeparateScannerProcess()) {
return false;
}
return this.monitorNotifiers.remove(monitorNotifier);
}
@Deprecated
public boolean removeMonitoreNotifier(MonitorNotifier monitorNotifier) {
return removeMonitorNotifier(monitorNotifier);
}
public boolean removeRangeNotifier(RangeNotifier rangeNotifier) {
return this.rangeNotifiers.remove(rangeNotifier);
}
public void requestStateForRegion(Region region) {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
RegionMonitoringState stateOf = MonitoringStatus.getInstanceForApplication(this.mContext).stateOf(region);
int i = (stateOf == null || !stateOf.getInside()) ? 0 : 1;
Iterator<MonitorNotifier> it = this.monitorNotifiers.iterator();
while (it.hasNext()) {
it.next().didDetermineStateForRegion(i, region);
}
}
public void setBackgroundBetweenScanPeriod(long j) {
this.backgroundBetweenScanPeriod = j;
if (Build.VERSION.SDK_INT < 26 || j >= 900000) {
return;
}
LogManager.w(TAG, "Setting a short backgroundBetweenScanPeriod has no effect on Android 8+, which is limited to scanning every ~15 minutes", new Object[0]);
}
@Deprecated
public void setBackgroundMode(boolean z) {
setBackgroundModeInternal(z);
}
public void setBackgroundModeInternal(boolean z) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
this.mBackgroundModeUninitialized = false;
if (z != this.mBackgroundMode) {
if (!z && getIntentScanStrategyCoordinator() != null) {
getIntentScanStrategyCoordinator().performPeriodicProcessing(this.mContext);
}
this.mBackgroundMode = z;
try {
updateScanPeriods();
} catch (RemoteException unused) {
LogManager.e(TAG, "Cannot contact service to set scan periods", new Object[0]);
}
}
}
public void setBackgroundScanPeriod(long j) {
this.backgroundScanPeriod = j;
}
public void setDataRequestNotifier(RangeNotifier rangeNotifier) {
this.dataRequestNotifier = rangeNotifier;
}
public void setEnableScheduledScanJobs(boolean z) {
if (isAnyConsumerBound()) {
LogManager.e(TAG, "ScanJob may not be configured because a consumer is already bound.", new Object[0]);
throw new IllegalStateException("Method must be called before starting ranging or monitoring");
}
if (!z && Build.VERSION.SDK_INT >= 26) {
LogManager.w(TAG, "Disabling ScanJobs on Android 8+ may disable delivery of beacon callbacks in the background unless a foreground service is active.", new Object[0]);
}
if (!z) {
ScanJobScheduler.getInstance().cancelSchedule(this.mContext);
}
this.mScheduledScanJobsEnabled = z;
}
public void setForegroundBetweenScanPeriod(long j) {
this.foregroundBetweenScanPeriod = j;
}
public void setForegroundScanPeriod(long j) {
this.foregroundScanPeriod = j;
}
public void setIntentScanningStrategyEnabled(boolean z) {
if (isAnyConsumerBound()) {
LogManager.e(TAG, "IntentScanningStrategy may not be configured because a consumer is already bound.", new Object[0]);
throw new IllegalStateException("Method must be called before starting ranging or monitoring");
}
if (z && Build.VERSION.SDK_INT < 26) {
LogManager.e(TAG, "IntentScanningStrategy may not be configured because Intent Scanning is not availble prior to Android 8.0", new Object[0]);
} else if (!z || Build.VERSION.SDK_INT < 26) {
this.mIntentScanStrategyCoordinator = null;
} else {
ScanJobScheduler.getInstance().cancelSchedule(this.mContext);
this.mIntentScanStrategyCoordinator = new IntentScanStrategyCoordinator(this.mContext);
}
}
public void setMaxTrackingAge(int i) {
RangedBeacon.setMaxTrackinAge(i);
}
@Deprecated
public void setMonitorNotifier(MonitorNotifier monitorNotifier) {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
this.monitorNotifiers.clear();
if (monitorNotifier != null) {
addMonitorNotifier(monitorNotifier);
}
}
public void setNonBeaconLeScanCallback(NonBeaconLeScanCallback nonBeaconLeScanCallback) {
this.mNonBeaconLeScanCallback = nonBeaconLeScanCallback;
}
@Deprecated
public void setRangeNotifier(RangeNotifier rangeNotifier) {
this.rangeNotifiers.clear();
if (rangeNotifier != null) {
addRangeNotifier(rangeNotifier);
}
}
@Deprecated
public void setRegionStatePeristenceEnabled(boolean z) {
setRegionStatePersistenceEnabled(z);
}
public void setRegionStatePersistenceEnabled(boolean z) {
this.mRegionStatePersistenceEnabled = z;
if (!isScannerInDifferentProcess()) {
if (z) {
MonitoringStatus.getInstanceForApplication(this.mContext).startStatusPreservation();
} else {
MonitoringStatus.getInstanceForApplication(this.mContext).stopStatusPreservation();
}
}
applySettings();
}
public void setScannerInSameProcess(boolean z) {
this.mScannerInSameProcess = Boolean.valueOf(z);
}
public boolean shutdownIfIdle() {
BeaconConsumer beaconConsumer;
if (this.autoBindConsumer == null || this.rangedRegions.size() != 0 || getMonitoredRegions().size() != 0 || (beaconConsumer = this.autoBindConsumer) == null) {
return false;
}
unbindInternal(beaconConsumer);
this.autoBindConsumer = null;
return true;
}
@TargetApi(18)
public void startMonitoring(Region region) {
ensureBackgroundPowerSaver();
if (isAnyConsumerBound()) {
try {
startMonitoringBeaconsInRegion(region);
return;
} catch (RemoteException e) {
LogManager.e(TAG, "Failed to start monitoring", e);
return;
}
}
synchronized (this.autoBindMonitoredRegions) {
this.autoBindMonitoredRegions.remove(region);
this.autoBindMonitoredRegions.add(region);
}
autoBind();
}
@TargetApi(18)
@Deprecated
public void startMonitoringBeaconsInRegion(Region region) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
if (!isScannerInDifferentProcess()) {
MonitoringStatus.getInstanceForApplication(this.mContext).addRegion(region, new Callback(callbackPackageName()));
}
applyChangesToServices(4, region);
if (isScannerInDifferentProcess()) {
MonitoringStatus.getInstanceForApplication(this.mContext).addLocalRegion(region);
}
requestStateForRegion(region);
}
@TargetApi(18)
public void startRangingBeacons(Region region) {
LogManager.d(TAG, "startRanging", new Object[0]);
ensureBackgroundPowerSaver();
if (isAnyConsumerBound()) {
try {
startRangingBeaconsInRegion(region);
return;
} catch (RemoteException e) {
LogManager.e(TAG, "Failed to start ranging", e);
return;
}
}
synchronized (this.autoBindRangedRegions) {
this.autoBindRangedRegions.remove(region);
this.autoBindRangedRegions.add(region);
}
autoBind();
}
@TargetApi(18)
@Deprecated
public void startRangingBeaconsInRegion(Region region) {
LogManager.d(TAG, "startRangingBeaconsInRegion", new Object[0]);
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
} else {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
this.rangedRegions.remove(region);
this.rangedRegions.add(region);
applyChangesToServices(2, region);
}
}
@TargetApi(18)
public void stopMonitoring(Region region) {
ensureBackgroundPowerSaver();
if (isAnyConsumerBound()) {
try {
stopMonitoringBeaconsInRegion(region);
return;
} catch (RemoteException e) {
LogManager.e(TAG, "Failed to stop monitoring", e);
return;
}
}
synchronized (this.autoBindMonitoredRegions) {
this.autoBindMonitoredRegions.remove(region);
MonitoringStatus.getInstanceForApplication(this.mContext).removeRegion(region);
}
}
@TargetApi(18)
@Deprecated
public void stopMonitoringBeaconsInRegion(Region region) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
if (!isScannerInDifferentProcess()) {
MonitoringStatus.getInstanceForApplication(this.mContext).removeRegion(region);
}
applyChangesToServices(5, region);
if (isScannerInDifferentProcess()) {
MonitoringStatus.getInstanceForApplication(this.mContext).removeLocalRegion(region);
}
autoUnbindIfNeeded();
}
@TargetApi(18)
public void stopRangingBeacons(Region region) {
LogManager.d(TAG, "stopRangingBeacons", new Object[0]);
ensureBackgroundPowerSaver();
if (isAnyConsumerBound()) {
try {
stopRangingBeaconsInRegion(region);
} catch (RemoteException e) {
LogManager.e(TAG, "Cannot stop ranging", e);
}
} else {
synchronized (this.autoBindMonitoredRegions) {
this.autoBindRangedRegions.remove(region);
}
}
autoUnbindIfNeeded();
}
@TargetApi(18)
@Deprecated
public void stopRangingBeaconsInRegion(Region region) {
LogManager.d(TAG, "stopRangingBeaconsInRegion", new Object[0]);
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
} else {
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
this.rangedRegions.remove(region);
applyChangesToServices(3, region);
}
}
public void syncSettingsToService() {
IntentScanStrategyCoordinator intentScanStrategyCoordinator = this.mIntentScanStrategyCoordinator;
if (intentScanStrategyCoordinator != null) {
intentScanStrategyCoordinator.applySettings();
return;
}
if (this.mScheduledScanJobsEnabled) {
ScanJobScheduler.getInstance().applySettingsToScheduledJob(this.mContext, this);
return;
}
try {
applyChangesToServices(7, null);
} catch (RemoteException e) {
LogManager.e(TAG, "Failed to sync settings to service", e);
}
}
@Deprecated
public void unbind(BeaconConsumer beaconConsumer) {
unbindInternal(beaconConsumer);
}
public void unbindInternal(InternalBeaconConsumer internalBeaconConsumer) {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
synchronized (this.consumers) {
if (this.consumers.containsKey(internalBeaconConsumer)) {
LogManager.d(TAG, "Unbinding", new Object[0]);
if (this.mIntentScanStrategyCoordinator != null) {
LogManager.d(TAG, "Not unbinding as we are using intent scanning strategy", new Object[0]);
} else if (this.mScheduledScanJobsEnabled) {
LogManager.d(TAG, "Not unbinding from scanning service as we are using scan jobs.", new Object[0]);
} else {
internalBeaconConsumer.unbindService(this.consumers.get(internalBeaconConsumer).beaconServiceConnection);
}
LogManager.d(TAG, "Before unbind, consumer count is " + this.consumers.size(), new Object[0]);
this.consumers.remove(internalBeaconConsumer);
LogManager.d(TAG, "After unbind, consumer count is " + this.consumers.size(), new Object[0]);
if (this.consumers.size() == 0) {
this.serviceMessenger = null;
if (this.mScheduledScanJobsEnabled || this.mIntentScanStrategyCoordinator != null) {
LogManager.i(TAG, "Cancelling scheduled jobs after unbind of last consumer.", new Object[0]);
ScanJobScheduler.getInstance().cancelSchedule(this.mContext);
}
}
} else {
LogManager.d(TAG, "This consumer is not bound to: %s", internalBeaconConsumer);
LogManager.d(TAG, "Bound consumers: ", new Object[0]);
Iterator<Map.Entry<InternalBeaconConsumer, ConsumerInfo>> it = this.consumers.entrySet().iterator();
while (it.hasNext()) {
LogManager.d(TAG, String.valueOf(it.next().getValue()), new Object[0]);
}
}
}
}
@TargetApi(18)
public void updateScanPeriods() {
if (!isBleAvailableOrSimulated()) {
LogManager.w(TAG, "Method invocation will be ignored.", new Object[0]);
return;
}
if (determineIfCalledFromSeparateScannerProcess()) {
return;
}
LogManager.d(TAG, "updating background flag to %s", Boolean.valueOf(this.mBackgroundMode));
LogManager.d(TAG, "updating scan period to %s, %s", Long.valueOf(getScanPeriod()), Long.valueOf(getBetweenScanPeriod()));
if (isAnyConsumerBound()) {
applyChangesToServices(6, null);
}
}
@Deprecated
public static void logDebug(String str, String str2, Throwable th) {
LogManager.d(th, str, str2, new Object[0]);
}
}