Monitor connectivity change and display offline promo.
Bug: 28141203 Change-Id: I2af7cc3071d835092fba961ff59189f1fb295063
This commit is contained in:
@@ -7475,12 +7475,21 @@
|
|||||||
<!-- Summary text for connecting to customer support [CHAR LIMIT=NONE]-->
|
<!-- Summary text for connecting to customer support [CHAR LIMIT=NONE]-->
|
||||||
<string name="support_escalation_summary">Call or email us and we\'ll get your issue solved right away. No muss, no fuss.</string>
|
<string name="support_escalation_summary">Call or email us and we\'ll get your issue solved right away. No muss, no fuss.</string>
|
||||||
|
|
||||||
|
<!-- Title text that indicates there is not internet connection. [CHAR LIMIT=80]-->
|
||||||
|
<string name="support_offline_title">You\'re offline</string>
|
||||||
|
|
||||||
|
<!-- Summary text telling user to connect to Internet in order to request customer support. [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="support_offline_summary">To reach support, first connect to Wi-Fi or data.</string>
|
||||||
|
|
||||||
<!-- Title text for showing a list of help options [CHAR LIMIT=80]-->
|
<!-- Title text for showing a list of help options [CHAR LIMIT=80]-->
|
||||||
<string name="support_more_help_title">More help</string>
|
<string name="support_more_help_title">More help</string>
|
||||||
|
|
||||||
<!-- Button label for contacting customer support by phone [CHAR LIMIT=20]-->
|
<!-- Button label for contacting customer support by phone [CHAR LIMIT=20]-->
|
||||||
<string name="support_escalation_by_phone">Phone</string>
|
<string name="support_escalation_by_phone">Phone</string>
|
||||||
|
|
||||||
|
<!-- Button label for contacting customer support by phone [CHAR LIMIT=20]-->
|
||||||
|
<string name="support_escalation_by_phone_offline">Phone</string>
|
||||||
|
|
||||||
<!-- Button label for contacting customer support by email [CHAR LIMIT=20]-->
|
<!-- Button label for contacting customer support by email [CHAR LIMIT=20]-->
|
||||||
<string name="support_escalation_by_email">Email</string>
|
<string name="support_escalation_by_email">Email</string>
|
||||||
|
|
||||||
|
@@ -20,7 +20,15 @@ import android.accounts.Account;
|
|||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.accounts.OnAccountsUpdateListener;
|
import android.accounts.OnAccountsUpdateListener;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.Network;
|
||||||
|
import android.net.NetworkCapabilities;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
|
import android.net.NetworkRequest;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -38,12 +46,34 @@ import com.android.settings.overlay.SupportFeatureProvider;
|
|||||||
public final class SupportFragment extends InstrumentedFragment implements View.OnClickListener,
|
public final class SupportFragment extends InstrumentedFragment implements View.OnClickListener,
|
||||||
OnAccountsUpdateListener {
|
OnAccountsUpdateListener {
|
||||||
|
|
||||||
|
private final Handler mHandler = new Handler(Looper.getMainLooper());
|
||||||
|
private final ConnectivityManager.NetworkCallback mNetworkCallback =
|
||||||
|
new ConnectivityManager.NetworkCallback() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCapabilitiesChanged(Network network,
|
||||||
|
NetworkCapabilities capabilities) {
|
||||||
|
postConnectivityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAvailable(Network network) {
|
||||||
|
postConnectivityChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLost(Network network) {
|
||||||
|
postConnectivityChanged();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
private View mContent;
|
private View mContent;
|
||||||
private RecyclerView mRecyclerView;
|
private RecyclerView mRecyclerView;
|
||||||
private SupportItemAdapter mSupportItemAdapter;
|
private SupportItemAdapter mSupportItemAdapter;
|
||||||
private AccountManager mAccountManager;
|
private AccountManager mAccountManager;
|
||||||
private SupportFeatureProvider mSupportFeatureProvider;
|
private SupportFeatureProvider mSupportFeatureProvider;
|
||||||
|
private ConnectivityManager mConnectivityManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getMetricsCategory() {
|
protected int getMetricsCategory() {
|
||||||
@@ -59,6 +89,8 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
|
FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
|
||||||
mSupportItemAdapter = new SupportItemAdapter(mActivity, mSupportFeatureProvider,
|
mSupportItemAdapter = new SupportItemAdapter(mActivity, mSupportFeatureProvider,
|
||||||
this /* itemClickListener */);
|
this /* itemClickListener */);
|
||||||
|
mConnectivityManager =
|
||||||
|
(ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -78,6 +110,12 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
// Monitor account change.
|
// Monitor account change.
|
||||||
mAccountManager.addOnAccountsUpdatedListener(
|
mAccountManager.addOnAccountsUpdatedListener(
|
||||||
this /* listener */, null /* handler */, true /* updateImmediately */);
|
this /* listener */, null /* handler */, true /* updateImmediately */);
|
||||||
|
// Monitor connectivity
|
||||||
|
mConnectivityManager.registerNetworkCallback(
|
||||||
|
new NetworkRequest.Builder()
|
||||||
|
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
|
||||||
|
.build(),
|
||||||
|
mNetworkCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -85,6 +123,8 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
super.onPause();
|
super.onPause();
|
||||||
// Stop monitor account change.
|
// Stop monitor account change.
|
||||||
mAccountManager.removeOnAccountsUpdatedListener(this /* listener */);
|
mAccountManager.removeOnAccountsUpdatedListener(this /* listener */);
|
||||||
|
// Stop monitor connectivity.
|
||||||
|
mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -99,4 +139,20 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
(SupportItemAdapter.ViewHolder) mRecyclerView.getChildViewHolder(v);
|
(SupportItemAdapter.ViewHolder) mRecyclerView.getChildViewHolder(v);
|
||||||
mSupportItemAdapter.onItemClicked(vh.getAdapterPosition());
|
mSupportItemAdapter.onItemClicked(vh.getAdapterPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void postConnectivityChanged() {
|
||||||
|
mHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mSupportItemAdapter != null) {
|
||||||
|
mSupportItemAdapter.setHasInternet(hasInternet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasInternet() {
|
||||||
|
final NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
|
||||||
|
return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import android.annotation.StringRes;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -43,6 +44,8 @@ import static com.android.settings.overlay.SupportFeatureProvider.SupportType.PH
|
|||||||
*/
|
*/
|
||||||
public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAdapter.ViewHolder> {
|
public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
private static final String TAG = "SupportItemAdapter";
|
||||||
|
|
||||||
private static final int TYPE_TITLE = R.layout.support_item_title;
|
private static final int TYPE_TITLE = R.layout.support_item_title;
|
||||||
private static final int TYPE_SUBTITLE = R.layout.support_item_subtitle;
|
private static final int TYPE_SUBTITLE = R.layout.support_item_subtitle;
|
||||||
private static final int TYPE_ESCALATION_CARD = R.layout.support_escalation_card;
|
private static final int TYPE_ESCALATION_CARD = R.layout.support_escalation_card;
|
||||||
@@ -53,12 +56,16 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
private final View.OnClickListener mItemClickListener;
|
private final View.OnClickListener mItemClickListener;
|
||||||
private final List<SupportData> mSupportData;
|
private final List<SupportData> mSupportData;
|
||||||
|
|
||||||
|
private boolean mHasInternet;
|
||||||
|
|
||||||
public SupportItemAdapter(Activity activity, SupportFeatureProvider supportFeatureProvider,
|
public SupportItemAdapter(Activity activity, SupportFeatureProvider supportFeatureProvider,
|
||||||
View.OnClickListener itemClickListener) {
|
View.OnClickListener itemClickListener) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mSupportFeatureProvider = supportFeatureProvider;
|
mSupportFeatureProvider = supportFeatureProvider;
|
||||||
mItemClickListener = itemClickListener;
|
mItemClickListener = itemClickListener;
|
||||||
mSupportData = new ArrayList<>();
|
mSupportData = new ArrayList<>();
|
||||||
|
// Optimistically assume we have Internet access. It will be updated later to correct value.
|
||||||
|
mHasInternet = true;
|
||||||
setHasStableIds(true);
|
setHasStableIds(true);
|
||||||
refreshData();
|
refreshData();
|
||||||
}
|
}
|
||||||
@@ -106,6 +113,13 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHasInternet(boolean hasInternet) {
|
||||||
|
if (mHasInternet != hasInternet) {
|
||||||
|
mHasInternet = hasInternet;
|
||||||
|
refreshData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create data for the adapter. If there is already data in the adapter, they will be
|
* Create data for the adapter. If there is already data in the adapter, they will be
|
||||||
* destroyed and recreated.
|
* destroyed and recreated.
|
||||||
@@ -113,7 +127,9 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
public void refreshData() {
|
public void refreshData() {
|
||||||
mSupportData.clear();
|
mSupportData.clear();
|
||||||
final Account[] accounts = mSupportFeatureProvider.getSupportEligibleAccounts(mActivity);
|
final Account[] accounts = mSupportFeatureProvider.getSupportEligibleAccounts(mActivity);
|
||||||
if (accounts.length > 0) {
|
if (accounts.length == 0) {
|
||||||
|
Log.d(TAG, "Account unavailable. Skipping");
|
||||||
|
} else {
|
||||||
addEscalationCards(accounts[0]);
|
addEscalationCards(accounts[0]);
|
||||||
}
|
}
|
||||||
addMoreHelpItems();
|
addMoreHelpItems();
|
||||||
@@ -121,9 +137,15 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addEscalationCards(Account account) {
|
private void addEscalationCards(Account account) {
|
||||||
mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
|
if (mHasInternet) {
|
||||||
R.string.support_escalation_title, R.string.support_escalation_summary,
|
mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
|
||||||
null /* intent */));
|
R.string.support_escalation_title, R.string.support_escalation_summary,
|
||||||
|
null /* intent */));
|
||||||
|
} else {
|
||||||
|
mSupportData.add(new SupportData(TYPE_TITLE, 0 /* icon */,
|
||||||
|
R.string.support_offline_title, R.string.support_offline_summary,
|
||||||
|
null /* intent */));
|
||||||
|
}
|
||||||
if (mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE)) {
|
if (mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE)) {
|
||||||
mSupportData.add(new SupportData(TYPE_ESCALATION_CARD, R.drawable.ic_call_24dp,
|
mSupportData.add(new SupportData(TYPE_ESCALATION_CARD, R.drawable.ic_call_24dp,
|
||||||
R.string.support_escalation_by_phone, 0 /* summary */,
|
R.string.support_escalation_by_phone, 0 /* summary */,
|
||||||
|
Reference in New Issue
Block a user