Make TetherSettings use the new tether api.

The new API handles all the provisioning logic so this area can
get significant code cleanup.

Change-Id: I4bcffb14b3ce26a01d17ec149599d63b0b4392f1
This commit is contained in:
Jeremy Klein
2016-01-25 14:43:49 -08:00
parent 91e0ba7d40
commit e3e7b95312
5 changed files with 128 additions and 180 deletions

View File

@@ -29,6 +29,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.os.IBinder;
import android.os.ResultReceiver;
@@ -121,13 +122,7 @@ public class TetherService extends Service {
int index = mCurrentTethers.indexOf(type);
if (DEBUG) Log.d(TAG, "Removing tether " + type + ", index " + index);
if (index >= 0) {
mCurrentTethers.remove(index);
// If we are currently in the middle of a check, we may need to adjust the
// index accordingly.
if (DEBUG) Log.d(TAG, "mCurrentTypeIndex: " + mCurrentTypeIndex);
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
mCurrentTypeIndex--;
}
removeTypeAtIndex(index);
}
cancelAlarmIfNecessary();
} else {
@@ -170,6 +165,16 @@ public class TetherService extends Service {
super.onDestroy();
}
private void removeTypeAtIndex(int index) {
mCurrentTethers.remove(index);
// If we are currently in the middle of a check, we may need to adjust the
// index accordingly.
if (DEBUG) Log.d(TAG, "mCurrentTypeIndex: " + mCurrentTypeIndex);
if (index <= mCurrentTypeIndex && mCurrentTypeIndex > 0) {
mCurrentTypeIndex--;
}
}
private ArrayList<Integer> stringToTethers(String tethersStr) {
ArrayList<Integer> ret = new ArrayList<Integer>();
if (TextUtils.isEmpty(tethersStr)) return ret;
@@ -227,8 +232,20 @@ public class TetherService extends Service {
if (DEBUG) Log.d(TAG, "Sending provisioning broadcast: " + provisionAction + " type: "
+ mCurrentTethers.get(index));
Intent intent = new Intent(provisionAction);
intent.putExtra(TETHER_CHOICE, mCurrentTethers.get(index));
int type = mCurrentTethers.get(index);
intent.putExtra(TETHER_CHOICE, type);
intent.setFlags(Intent.FLAG_RECEIVER_FOREGROUND);
// Ensure that the provisioning app will actually handle the intent.
final PackageManager packageManager = getPackageManager();
if (packageManager.queryBroadcastReceivers(
intent, PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
Log.e(TAG, "Provisioning app is configured, but not available.");
fireCallbacksForType(type, ConnectivityManager.TETHER_ERROR_PROVISION_FAILED);
removeTypeAtIndex(index);
return;
}
sendBroadcast(intent);
mInProvisionCheck = true;
}