am 5565b5cd
: Fix IndexOutOfBoundsException while silent provisioning check
* commit '5565b5cd7537e9360e6382507a45cf5e091a5108': Fix IndexOutOfBoundsException while silent provisioning check
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settingslib.TetherUtil;
|
import com.android.settingslib.TetherUtil;
|
||||||
|
|
||||||
@@ -14,11 +15,15 @@ import com.android.settingslib.TetherUtil;
|
|||||||
*/
|
*/
|
||||||
public class HotspotOffReceiver extends BroadcastReceiver {
|
public class HotspotOffReceiver extends BroadcastReceiver {
|
||||||
|
|
||||||
|
private static final String TAG = "HotspotOffReceiver";
|
||||||
|
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||||
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
|
||||||
if (wifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED) {
|
if (wifiManager.getWifiApState() == WifiManager.WIFI_AP_STATE_DISABLED) {
|
||||||
|
if (DEBUG) Log.d(TAG, "TetherService.cancelRecheckAlarmIfNecessary called");
|
||||||
// The hotspot has been turned off, we don't need to recheck tethering.
|
// The hotspot has been turned off, we don't need to recheck tethering.
|
||||||
TetherService.cancelRecheckAlarmIfNecessary(context, TetherUtil.TETHERING_WIFI);
|
TetherService.cancelRecheckAlarmIfNecessary(context, TetherUtil.TETHERING_WIFI);
|
||||||
}
|
}
|
||||||
|
@@ -89,21 +89,28 @@ public class TetherService extends Service {
|
|||||||
mCurrentTethers.add(type);
|
mCurrentTethers.add(type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (intent.hasExtra(TetherUtil.EXTRA_REM_TETHER_TYPE)) {
|
if (intent.hasExtra(TetherUtil.EXTRA_REM_TETHER_TYPE)) {
|
||||||
int type = intent.getIntExtra(TetherUtil.EXTRA_REM_TETHER_TYPE,
|
if (!mInProvisionCheck) {
|
||||||
TetherUtil.TETHERING_INVALID);
|
int type = intent.getIntExtra(TetherUtil.EXTRA_REM_TETHER_TYPE,
|
||||||
if (DEBUG) Log.d(TAG, "Removing tether " + type);
|
TetherUtil.TETHERING_INVALID);
|
||||||
int index = mCurrentTethers.indexOf(type);
|
int index = mCurrentTethers.indexOf(type);
|
||||||
if (index >= 0) {
|
if (DEBUG) Log.d(TAG, "Removing tether " + type + ", index " + index);
|
||||||
mCurrentTethers.remove(index);
|
if (index >= 0) {
|
||||||
// If we are currently in the middle of a check, we may need to adjust the
|
mCurrentTethers.remove(index);
|
||||||
// index accordingly.
|
// If we are currently in the middle of a check, we may need to adjust the
|
||||||
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
|
// index accordingly.
|
||||||
mCurrentTypeIndex--;
|
if (DEBUG) Log.d(TAG, "mCurrentTypeIndex: " + mCurrentTypeIndex);
|
||||||
|
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
|
||||||
|
mCurrentTypeIndex--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
cancelAlarmIfNecessary();
|
||||||
|
} else {
|
||||||
|
if (DEBUG) Log.d(TAG, "Don't cancel alarm during provisioning");
|
||||||
}
|
}
|
||||||
cancelAlarmIfNecessary();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only set the alarm if we have one tether, meaning the one just added,
|
// Only set the alarm if we have one tether, meaning the one just added,
|
||||||
// to avoid setting it when it was already set previously for another
|
// to avoid setting it when it was already set previously for another
|
||||||
// type.
|
// type.
|
||||||
@@ -199,15 +206,17 @@ public class TetherService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void startProvisioning(int index) {
|
private void startProvisioning(int index) {
|
||||||
String provisionAction = getResources().getString(
|
if (index < mCurrentTethers.size()) {
|
||||||
com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui);
|
String provisionAction = getResources().getString(
|
||||||
if (DEBUG) Log.d(TAG, "Sending provisioning broadcast: " + provisionAction + " type: "
|
com.android.internal.R.string.config_mobile_hotspot_provision_app_no_ui);
|
||||||
+ mCurrentTethers.get(index));
|
if (DEBUG) Log.d(TAG, "Sending provisioning broadcast: " + provisionAction + " type: "
|
||||||
Intent intent = new Intent(provisionAction);
|
+ mCurrentTethers.get(index));
|
||||||
intent.putExtra(TETHER_CHOICE, mCurrentTethers.get(index));
|
Intent intent = new Intent(provisionAction);
|
||||||
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
intent.putExtra(TETHER_CHOICE, mCurrentTethers.get(index));
|
||||||
sendBroadcast(intent);
|
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||||
mInProvisionCheck = true;
|
sendBroadcast(intent);
|
||||||
|
mInProvisionCheck = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void scheduleRecheckAlarm(Context context, int type) {
|
public static void scheduleRecheckAlarm(Context context, int type) {
|
||||||
@@ -261,13 +270,14 @@ public class TetherService extends Service {
|
|||||||
if (DEBUG) Log.d(TAG, "Got provision result " + intent);
|
if (DEBUG) Log.d(TAG, "Got provision result " + intent);
|
||||||
String provisionResponse = context.getResources().getString(
|
String provisionResponse = context.getResources().getString(
|
||||||
com.android.internal.R.string.config_mobile_hotspot_provision_response);
|
com.android.internal.R.string.config_mobile_hotspot_provision_response);
|
||||||
|
|
||||||
if (provisionResponse.equals(intent.getAction())) {
|
if (provisionResponse.equals(intent.getAction())) {
|
||||||
if (!mInProvisionCheck) {
|
if (!mInProvisionCheck) {
|
||||||
Log.e(TAG, "Unexpected provision response " + intent);
|
Log.e(TAG, "Unexpected provision response " + intent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mInProvisionCheck = false;
|
|
||||||
int checkType = mCurrentTethers.get(mCurrentTypeIndex);
|
int checkType = mCurrentTethers.get(mCurrentTypeIndex);
|
||||||
|
mInProvisionCheck = false;
|
||||||
if (intent.getIntExtra(EXTRA_RESULT, RESULT_DEFAULT) == RESULT_OK) {
|
if (intent.getIntExtra(EXTRA_RESULT, RESULT_DEFAULT) == RESULT_OK) {
|
||||||
if (checkType == TetherUtil.TETHERING_WIFI && mEnableWifiAfterCheck) {
|
if (checkType == TetherUtil.TETHERING_WIFI && mEnableWifiAfterCheck) {
|
||||||
enableWifiTetheringIfNeeded();
|
enableWifiTetheringIfNeeded();
|
||||||
@@ -286,7 +296,8 @@ public class TetherService extends Service {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (++mCurrentTypeIndex == mCurrentTethers.size()) {
|
|
||||||
|
if (++mCurrentTypeIndex >= mCurrentTethers.size()) {
|
||||||
// We are done with all checks, time to die.
|
// We are done with all checks, time to die.
|
||||||
stopSelf();
|
stopSelf();
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user