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"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.RickBarrette.android.LocationRinger"
|
package="org.RickBarrette.android.LocationRinger"
|
||||||
android:installLocation="internalOnly"
|
android:installLocation="internalOnly"
|
||||||
android:versionCode="209"
|
android:versionCode="219"
|
||||||
android:versionName="1.0" >
|
android:versionName="2a1fd40" >
|
||||||
|
|
||||||
<uses-sdk android:minSdkVersion="8" />
|
<uses-sdk android:minSdkVersion="8" />
|
||||||
|
|
||||||
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
<!-- licensing library -->
|
<!-- licensing library -->
|
||||||
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
|
<uses-permission android:name="com.android.vending.CHECK_LICENSE" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@@ -133,6 +134,12 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity android:name="LegalActivity" >
|
<activity android:name="LegalActivity" >
|
||||||
</activity>
|
</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>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</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.Constraints;
|
||||||
import org.RickBarrette.android.LocationRinger.Log;
|
import org.RickBarrette.android.LocationRinger.Log;
|
||||||
import org.RickBarrette.android.LocationRinger.db.RingerDatabase;
|
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.receivers.GetLocationWidget;
|
||||||
import org.RickBarrette.android.LocationRinger.ui.SettingsActivity;
|
import org.RickBarrette.android.LocationRinger.ui.SettingsActivity;
|
||||||
|
|
||||||
@@ -24,6 +25,8 @@ import android.database.Cursor;
|
|||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
@@ -105,18 +108,30 @@ public class RingerProcessingService extends Service {
|
|||||||
setStreamVolume(values.getAsInteger(RingerDatabase.KEY_ALARM_VOLUME), AudioManager.STREAM_ALARM);
|
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))
|
ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
||||||
if (mWifiManager != null)
|
NetworkInfo wifiNetInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||||
mWifiManager.setWifiEnabled(RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_WIFI)));
|
|
||||||
|
|
||||||
if (values.containsKey(RingerDatabase.KEY_BT))
|
if (! wifiNetInfo.isConnected())
|
||||||
if (mBluetoothAdapter != null)
|
if (values.containsKey(RingerDatabase.KEY_WIFI))
|
||||||
if (RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_BT)))
|
if (mWifiManager != null)
|
||||||
mBluetoothAdapter.enable();
|
mWifiManager.setWifiEnabled(RingerDatabase.parseBoolean(values.getAsString(RingerDatabase.KEY_WIFI)));
|
||||||
else
|
|
||||||
mBluetoothAdapter.disable();
|
/*
|
||||||
|
* 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
|
* airplane mode
|
||||||
|
|||||||
Reference in New Issue
Block a user