SetupWizard: Give radio a 10 second chance to come up

Change-Id: Iadd817b200106783dd67edbc5ad03928ce2baa6b
This commit is contained in:
cretin45 2015-04-14 17:28:37 -07:00 committed by Michael Bestas
parent bfd7ca0545
commit f654deb217
7 changed files with 185 additions and 41 deletions

View File

@ -21,6 +21,13 @@
<include layout="@layout/header" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp" />
<FrameLayout android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
@ -35,7 +42,8 @@
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/PageContent">
style="@style/PageContent"
android:visibility="gone">
<TextView
android:layout_width="match_parent"

View File

@ -21,6 +21,13 @@
<include layout="@layout/header" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp" />
<FrameLayout android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
@ -31,10 +38,12 @@
android:fillViewport="true">
<LinearLayout
android:id="@+id/page_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/PageContent">
style="@style/PageContent"
android:visibility="gone">
<TextView
android:id="@+id/mobile_data_summary"

View File

@ -21,6 +21,7 @@ import android.app.Application;
import android.app.StatusBarManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Handler;
import android.provider.Settings;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -59,8 +60,21 @@ public class SetupWizardApp extends Application {
public static final int REQUEST_CODE_SETUP_CYANOGEN= 3;
public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL= 4;
public static final int RADIO_READY_TIMEOUT = 10 * 1000;
private boolean mIsRadioReady = false;
private StatusBarManager mStatusBarManager;
private final Handler mHandler = new Handler();
private final Runnable mRadioTimeoutRunnable = new Runnable() {
@Override
public void run() {
mIsRadioReady = true;
}
};
@Override
public void onCreate() {
super.onCreate();
@ -84,6 +98,18 @@ public class SetupWizardApp extends Application {
// Continue with setup
disableCaptivePortalDetection();
}
mHandler.postDelayed(mRadioTimeoutRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
public boolean isRadioReady() {
return mIsRadioReady;
}
public void setRadioReady(boolean radioReady) {
if (!mIsRadioReady && radioReady) {
mHandler.removeCallbacks(mRadioTimeoutRunnable);
}
mIsRadioReady = radioReady;
}
public void disableStatusBar() {

View File

@ -44,10 +44,12 @@ public class CMSetupWizardData extends AbstractSetupData {
pages.add(new WelcomePage(mContext, this));
pages.add(new WifiSetupPage(mContext, this));
if (SetupWizardUtils.hasTelephony(mContext)) {
pages.add(new SimCardMissingPage(mContext, this).setHidden(isSimInserted()));
pages.add(new SimCardMissingPage(mContext, this)
.setHidden(isSimInserted()));
}
if (SetupWizardUtils.isMultiSimDevice(mContext)) {
pages.add(new ChooseDataSimPage(mContext, this).setHidden(!allSimsInserted()));
pages.add(new ChooseDataSimPage(mContext, this)
.setHidden(!allSimsInserted()));
}
if (SetupWizardUtils.hasTelephony(mContext)) {
pages.add(new MobileDataPage(mContext, this)
@ -68,19 +70,8 @@ public class CMSetupWizardData extends AbstractSetupData {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
ChooseDataSimPage chooseDataSimPage =
(ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
if (chooseDataSimPage != null) {
chooseDataSimPage.setHidden(!allSimsInserted());
}
SimCardMissingPage simCardMissingPage =
(SimCardMissingPage) getPage(SimCardMissingPage.TAG);
if (simCardMissingPage != null) {
simCardMissingPage.setHidden(isSimInserted());
if (isCurrentPage(simCardMissingPage)) {
onNextPage();
}
}
showHideDataSimPage();
showHideSimMissingPage();
showHideMobileDataPage();
} else if (intent.getAction()
.equals(ConnectivityManager.CONNECTIVITY_ACTION) ||
@ -116,12 +107,30 @@ public class CMSetupWizardData extends AbstractSetupData {
}
}
private void showHideSimMissingPage() {
SimCardMissingPage simCardMissingPage =
(SimCardMissingPage) getPage(SimCardMissingPage.TAG);
if (simCardMissingPage != null && isSimInserted()) {
simCardMissingPage.setHidden(true);
if (isCurrentPage(simCardMissingPage)) {
onNextPage();
}
}
}
private void showHideDataSimPage() {
ChooseDataSimPage chooseDataSimPage =
(ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
if (chooseDataSimPage != null) {
chooseDataSimPage.setHidden(!isSimInserted());
}
}
private void showHideMobileDataPage() {
MobileDataPage mobileDataPage =
(MobileDataPage) getPage(MobileDataPage.TAG);
if (mobileDataPage != null) {
mobileDataPage.setHidden(!isSimInserted() ||
SetupWizardUtils.isMobileDataEnabled(mContext));
mobileDataPage.setHidden(!isSimInserted());
}
}

View File

@ -20,6 +20,7 @@ import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
@ -31,15 +32,19 @@ import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.android.internal.telephony.SubscriptionController;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
import java.util.List;
@ -81,6 +86,7 @@ public class ChooseDataSimPage extends SetupPage {
public static class ChooseDataSimFragment extends SetupPageFragment {
private ViewGroup mPageView;
private ProgressBar mProgressBar;
private SparseArray<TextView> mNameViews;
private SparseArray<ImageView> mSignalViews;
private SparseArray<CheckBox> mCheckBoxes;
@ -93,6 +99,17 @@ public class ChooseDataSimPage extends SetupPage {
private boolean mIsAttached = false;
private Context mContext;
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = new Runnable() {
@Override
public void run() {
hideWaitForRadio();
}
};
private View.OnClickListener mSetDataSimClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
@ -108,6 +125,7 @@ public class ChooseDataSimPage extends SetupPage {
@Override
protected void initializePage() {
mPageView = (ViewGroup)mRootView.findViewById(R.id.page_view);
mProgressBar = (ProgressBar) mRootView.findViewById(R.id.progress);
List<SubscriptionInfo> subInfoRecords = SubscriptionController
.getInstance().getActiveSubscriptionInfoList();
int simCount = subInfoRecords.size();
@ -148,6 +166,7 @@ public class ChooseDataSimPage extends SetupPage {
public void onResume() {
super.onResume();
mIsAttached = true;
mContext = getActivity().getApplicationContext();
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
for (int i = 0; i < mPhoneStateListeners.size(); i++) {
mPhone.listen(mPhoneStateListeners.get(i),
@ -156,6 +175,12 @@ public class ChooseDataSimPage extends SetupPage {
}
updateSignalStrengths();
updateCurrentDataSub();
if (SetupWizardUtils.isRadioReady(mContext, null)) {
hideWaitForRadio();
} else if (mTitleView != null) {
mTitleView.setText(R.string.loading);
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
}
@Override
@ -172,22 +197,34 @@ public class ChooseDataSimPage extends SetupPage {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
if (mIsAttached) {
mSignalStrengths.put(subInfoRecord.getSimSlotIndex(), signalStrength);
updateSignalStrength(subInfoRecord);
}
mSignalStrengths.put(subInfoRecord.getSimSlotIndex(), signalStrength);
updateSignalStrength(subInfoRecord);
}
@Override
public void onServiceStateChanged(ServiceState state) {
if (mIsAttached) {
mServiceStates.put(subInfoRecord.getSimSlotIndex(), state);
updateSignalStrength(subInfoRecord);
if (SetupWizardUtils.isRadioReady(mContext, state)) {
hideWaitForRadio();
}
mServiceStates.put(subInfoRecord.getSimSlotIndex(), state);
updateSignalStrength(subInfoRecord);
}
};
}
private void hideWaitForRadio() {
if (getUserVisibleHint() && mProgressBar.isShown()) {
mHandler.removeCallbacks(mRadioReadyRunnable);
if (mTitleView != null) {
mTitleView.setText(mPage.getTitleResId());
}
mProgressBar.setVisibility(View.GONE);
mPageView.setVisibility(View.VISIBLE);
mPageView.startAnimation(
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
}
}
private void updateSignalStrengths() {
if (mIsAttached) {
for (int i = 0; i < mSubInfoRecords.size(); i++) {

View File

@ -20,6 +20,7 @@ import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
@ -27,11 +28,15 @@ import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import com.cyanogenmod.setupwizard.R;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.cyanogenmod.setupwizard.cmstats.SetupStats;
import com.cyanogenmod.setupwizard.ui.SetupPageFragment;
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
@ -69,6 +74,8 @@ public class MobileDataPage extends SetupPage {
public static class MobileDataFragment extends SetupPageFragment {
private ViewGroup mPageView;
private ProgressBar mProgressBar;
private View mEnableDataRow;
private Switch mEnableMobileData;
private ImageView mSignalView;
@ -80,26 +87,36 @@ public class MobileDataPage extends SetupPage {
private boolean mIsAttached = false;
private Context mContext;
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = new Runnable() {
@Override
public void run() {
hideWaitForRadio();
}
};
private PhoneStateListener mPhoneStateListener =
new PhoneStateListener(SubscriptionManager.getDefaultDataSubId()) {
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
if (mIsAttached) {
mSignalStrength = signalStrength;
updateSignalStrength();
}
}
@Override
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
mSignalStrength = signalStrength;
updateSignalStrength();
}
@Override
public void onServiceStateChanged(ServiceState state) {
if (mIsAttached) {
mServiceState = state;
updateSignalStrength();
}
}
@Override
public void onServiceStateChanged(ServiceState state) {
if (SetupWizardUtils.isRadioReady(mContext, state)) {
hideWaitForRadio();
}
mServiceState = state;
updateSignalStrength();
}
};
};
private View.OnClickListener mEnableDataClickListener = new View.OnClickListener() {
@Override
@ -115,6 +132,8 @@ public class MobileDataPage extends SetupPage {
@Override
protected void initializePage() {
mPageView = (ViewGroup)mRootView.findViewById(R.id.page_view);
mProgressBar = (ProgressBar) mRootView.findViewById(R.id.progress);
mEnableDataRow = mRootView.findViewById(R.id.data);
mEnableDataRow.setOnClickListener(mEnableDataClickListener);
mEnableMobileData = (Switch) mRootView.findViewById(R.id.data_switch);
@ -133,12 +152,19 @@ public class MobileDataPage extends SetupPage {
public void onResume() {
super.onResume();
mIsAttached = true;
mContext = getActivity().getApplicationContext();
mPhone = (TelephonyManager)getActivity().getSystemService(Context.TELEPHONY_SERVICE);
mPhone.listen(mPhoneStateListener,
PhoneStateListener.LISTEN_SERVICE_STATE
| PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
updateDataConnectionStatus();
updateSignalStrength();
if (SetupWizardUtils.isRadioReady(mContext, null)) {
hideWaitForRadio();
} else if (mTitleView != null) {
mTitleView.setText(R.string.loading);
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
}
@Override
@ -148,6 +174,19 @@ public class MobileDataPage extends SetupPage {
mPhone.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);
}
private void hideWaitForRadio() {
if (getUserVisibleHint() && mProgressBar.isShown()) {
mHandler.removeCallbacks(mRadioReadyRunnable);
if (mTitleView != null) {
mTitleView.setText(mPage.getTitleResId());
}
mProgressBar.setVisibility(View.GONE);
mPageView.setVisibility(View.VISIBLE);
mPageView.startAnimation(
AnimationUtils.loadAnimation(getActivity(), R.anim.translucent_enter));
}
}
private void updateCarrierText() {
if (mIsAttached) {
String name =

View File

@ -27,12 +27,15 @@ import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.android.internal.telephony.SubscriptionController;
import com.cyanogenmod.setupwizard.SetupWizardApp;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
@ -126,6 +129,19 @@ public class SetupWizardUtils {
return true;
}
public static boolean isRadioReady(Context context, ServiceState state) {
final SetupWizardApp setupWizardApp = (SetupWizardApp)context.getApplicationContext();
if (setupWizardApp.isRadioReady()) {
return true;
} else {
final boolean ready = state != null
&& state.getState() != ServiceState.STATE_POWER_OFF;
setupWizardApp.setRadioReady(ready);
return ready;
}
}
public static boolean isGuestUser(Context context) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
return userManager.isGuestUser();