Add a periodic check of the tethering provisioning

Add a service that handles the check through broadcasts which are
defined through configs, similar to the previous configs for the
activity.

Depends on I1f6e2d954562c5a16a0de60dac625005ec3e5c50

Bug: 18453076
Change-Id: I515d72706e9ca37877e67c44427af1b75b146390
diff --git a/src/com/android/settings/TetherSettings.java b/src/com/android/settings/TetherSettings.java
index 230bbb2..e33ddb0 100644
--- a/src/com/android/settings/TetherSettings.java
+++ b/src/com/android/settings/TetherSettings.java
@@ -93,10 +93,10 @@
 
     private boolean mBluetoothEnableForTether;
 
-    private static final int INVALID             = -1;
-    private static final int WIFI_TETHERING      = 0;
-    private static final int USB_TETHERING       = 1;
-    private static final int BLUETOOTH_TETHERING = 2;
+    public static final int INVALID             = -1;
+    public static final int WIFI_TETHERING      = 0;
+    public static final int USB_TETHERING       = 1;
+    public static final int BLUETOOTH_TETHERING = 2;
 
     /* One of INVALID, WIFI_TETHERING, USB_TETHERING or BLUETOOTH_TETHERING */
     private int mTetherChoice = INVALID;
@@ -456,6 +456,9 @@
         if (enable) {
             startProvisioningIfNecessary(WIFI_TETHERING);
         } else {
+            if (isProvisioningNeeded(mProvisionApp)) {
+                TetherService.cancelRecheckAlarmIfNecessary(getActivity(), WIFI_TETHERING);
+            }
             mWifiApEnabler.setSoftapEnabled(false);
         }
         return false;
@@ -505,6 +508,7 @@
         super.onActivityResult(requestCode, resultCode, intent);
         if (requestCode == PROVISION_REQUEST) {
             if (resultCode == Activity.RESULT_OK) {
+                TetherService.scheduleRecheckAlarm(getActivity(), mTetherChoice);
                 startTethering();
             } else {
                 //BT and USB need switch turned off on failure
@@ -572,6 +576,9 @@
             if (newState) {
                 startProvisioningIfNecessary(USB_TETHERING);
             } else {
+                if (isProvisioningNeeded(mProvisionApp)) {
+                    TetherService.cancelRecheckAlarmIfNecessary(getActivity(), USB_TETHERING);
+                }
                 setUsbTethering(newState);
             }
         } else if (preference == mBluetoothTether) {
@@ -580,6 +587,9 @@
             if (bluetoothTetherState) {
                 startProvisioningIfNecessary(BLUETOOTH_TETHERING);
             } else {
+                if (isProvisioningNeeded(mProvisionApp)) {
+                    TetherService.cancelRecheckAlarmIfNecessary(getActivity(), BLUETOOTH_TETHERING);
+                }
                 boolean errored = false;
 
                 String [] tethered = cm.getTetheredIfaces();