Do not turn off WIFI or BT while in use.
Added if blocks to check if WIFI or BT is in used before changing their state. Also added a new receiver to monitor the number of connected BT devices Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.RickBarrette.android.LocationRinger"
|
||||
android:installLocation="internalOnly"
|
||||
android:versionCode="209"
|
||||
android:versionName="1.0" >
|
||||
android:versionCode="219"
|
||||
android:versionName="2a1fd40" >
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
|
||||
<!-- licensing library -->
|
||||
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -133,6 +134,12 @@
|
||||
</activity>
|
||||
<activity android:name="LegalActivity" >
|
||||
</activity>
|
||||
<receiver android:name=".receivers.BluetoothReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.bluetooth.device.action.ACL_CONNECTED"/>
|
||||
<action android:name="android.bluetooth.device.action.ACL_DISCONNECTED"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* BluetoothReceiver.java
|
||||
* @date Jan 4, 2013
|
||||
* @author ricky barrette
|
||||
*
|
||||
* Copyright 2012 Richard Barrette
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package org.RickBarrette.android.LocationRinger.receivers;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
|
||||
/**
|
||||
* This class will be used to maintain a log of connected devices
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public class BluetoothReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String TAG = "BluetoothReceiver";
|
||||
public static final String NUMBER_CONNECTED = "number_connected";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(TAG, Context.MODE_MULTI_PROCESS);
|
||||
Editor editor = sp.edit();
|
||||
int connected = sp.getInt(NUMBER_CONNECTED, 0);
|
||||
|
||||
if (BluetoothDevice.ACTION_ACL_CONNECTED.equals(action))
|
||||
connected++;
|
||||
|
||||
else if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action))
|
||||
connected--;
|
||||
|
||||
editor.putInt(NUMBER_CONNECTED, connected);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import java.util.Map.Entry;
|
||||
import org.RickBarrette.android.LocationRinger.Constraints;
|
||||
import org.RickBarrette.android.LocationRinger.Log;
|
||||
import org.RickBarrette.android.LocationRinger.db.RingerDatabase;
|
||||
import org.RickBarrette.android.LocationRinger.receivers.BluetoothReceiver;
|
||||
import org.RickBarrette.android.LocationRinger.receivers.GetLocationWidget;
|
||||
import org.RickBarrette.android.LocationRinger.ui.SettingsActivity;
|
||||
|
||||
@@ -24,6 +25,8 @@ import android.database.Cursor;
|
||||
import android.location.Location;
|
||||
import android.media.AudioManager;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.Uri;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.IBinder;
|
||||
@@ -105,18 +108,30 @@ public class RingerProcessingService extends Service {
|
||||
setStreamVolume(values.getAsInteger(RingerDatabase.KEY_ALARM_VOLUME), AudioManager.STREAM_ALARM);
|
||||
|
||||
/*
|
||||
* wifi & bluetooth
|
||||
* wifi
|
||||
*
|
||||
* only change wifi state IF NOT connected
|
||||
*/
|
||||
if (values.containsKey(RingerDatabase.KEY_WIFI))
|
||||
if (mWifiManager != null)
|
||||
mWifiManager.setWifiEnabled(RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_WIFI)));
|
||||
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
||||
NetworkInfo wifiNetInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
|
||||
if (values.containsKey(RingerDatabase.KEY_BT))
|
||||
if (mBluetoothAdapter != null)
|
||||
if (RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_BT)))
|
||||
mBluetoothAdapter.enable();
|
||||
else
|
||||
mBluetoothAdapter.disable();
|
||||
if (! wifiNetInfo.isConnected())
|
||||
if (values.containsKey(RingerDatabase.KEY_WIFI))
|
||||
if (mWifiManager != null)
|
||||
mWifiManager.setWifiEnabled(RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_WIFI)));
|
||||
|
||||
/*
|
||||
* bluetooth
|
||||
*
|
||||
* only updated bt state IF NOT connected
|
||||
*/
|
||||
if(getSharedPreferences(BluetoothReceiver.TAG, Context.MODE_MULTI_PROCESS).getInt(BluetoothReceiver.NUMBER_CONNECTED, 0) < 1)
|
||||
if (values.containsKey(RingerDatabase.KEY_BT))
|
||||
if (mBluetoothAdapter != null)
|
||||
if (RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_BT)))
|
||||
mBluetoothAdapter.enable();
|
||||
else
|
||||
mBluetoothAdapter.disable();
|
||||
|
||||
/*
|
||||
* airplane mode
|
||||
|
||||
Reference in New Issue
Block a user