2015-01-16 00:04:44 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 The CyanogenMod Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.cyanogenmod.setupwizard.setup;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-01-30 01:36:30 +00:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.IntentFilter;
|
2015-02-13 18:51:10 +00:00
|
|
|
import android.net.ConnectivityManager;
|
2015-05-07 21:05:29 +00:00
|
|
|
import android.os.SystemProperties;
|
2015-04-27 20:20:13 +00:00
|
|
|
import android.telephony.SubscriptionManager;
|
2015-01-30 01:36:30 +00:00
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
|
2015-06-18 23:21:06 +00:00
|
|
|
import android.util.Log;
|
2015-01-30 01:36:30 +00:00
|
|
|
import com.android.internal.telephony.TelephonyIntents;
|
2015-12-21 16:55:35 +00:00
|
|
|
import com.cyanogenmod.setupwizard.R;
|
2015-01-30 01:36:30 +00:00
|
|
|
import com.cyanogenmod.setupwizard.util.SetupWizardUtils;
|
2015-01-16 00:04:44 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class CMSetupWizardData extends AbstractSetupData {
|
|
|
|
|
2015-01-30 01:36:30 +00:00
|
|
|
private static final String TAG = CMSetupWizardData.class.getSimpleName();
|
|
|
|
|
|
|
|
private boolean mTimeSet = false;
|
|
|
|
private boolean mTimeZoneSet = false;
|
2015-07-21 17:07:43 +00:00
|
|
|
private boolean mMobileDataEnabled;
|
2015-01-30 01:36:30 +00:00
|
|
|
|
2015-02-23 21:52:37 +00:00
|
|
|
public CMSetupWizardData(Context context) {
|
2015-01-16 00:04:44 +00:00
|
|
|
super(context);
|
2015-07-21 17:07:43 +00:00
|
|
|
mMobileDataEnabled = SetupWizardUtils.isMobileDataEnabled(context);
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected PageList onNewPageList() {
|
2015-01-30 01:36:30 +00:00
|
|
|
ArrayList<Page> pages = new ArrayList<Page>();
|
2015-04-24 02:54:36 +00:00
|
|
|
if (SetupWizardUtils.hasLeanback(mContext)) {
|
|
|
|
pages.add(new BluetoothSetupPage(mContext, this));
|
|
|
|
}
|
2015-01-16 00:04:44 +00:00
|
|
|
pages.add(new WelcomePage(mContext, this));
|
2016-12-29 16:28:02 +00:00
|
|
|
pages.add(new LocalePage(mContext, this));
|
|
|
|
pages.add(new DateTimePage(mContext, this));
|
2016-09-07 16:44:31 +00:00
|
|
|
if (SetupWizardUtils.hasWifi(mContext)) {
|
|
|
|
pages.add(new WifiSetupPage(mContext, this));
|
|
|
|
}
|
2015-01-30 21:56:47 +00:00
|
|
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
2015-04-15 00:28:37 +00:00
|
|
|
pages.add(new SimCardMissingPage(mContext, this)
|
|
|
|
.setHidden(isSimInserted()));
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
2015-03-12 20:50:19 +00:00
|
|
|
if (SetupWizardUtils.isMultiSimDevice(mContext)) {
|
2015-04-15 00:28:37 +00:00
|
|
|
pages.add(new ChooseDataSimPage(mContext, this)
|
|
|
|
.setHidden(!allSimsInserted()));
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
2015-02-05 01:13:57 +00:00
|
|
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
|
|
|
pages.add(new MobileDataPage(mContext, this)
|
2015-05-07 21:05:29 +00:00
|
|
|
.setHidden(!isSimInserted() || mMobileDataEnabled));
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
2016-05-13 22:34:56 +00:00
|
|
|
final boolean hasGMS = SetupWizardUtils.hasGMS(mContext);
|
|
|
|
if (hasGMS) {
|
|
|
|
pages.add(new GmsAccountPage(mContext, this));
|
2015-01-16 00:04:44 +00:00
|
|
|
}
|
2016-12-29 16:28:02 +00:00
|
|
|
pages.add(new OtherSettingsPage(mContext, this).setHidden(!hasGMS));
|
2015-07-13 19:02:23 +00:00
|
|
|
if (SetupWizardUtils.hasFingerprint(mContext) && SetupWizardUtils.isOwner()) {
|
|
|
|
pages.add(new FingerprintSetupPage(mContext, this));
|
2016-08-10 11:33:05 +00:00
|
|
|
} else if (SetupWizardUtils.frpEnabled(mContext)) {
|
|
|
|
pages.add(new ScreenLockSetupPage(mContext, this));
|
2015-07-13 19:02:23 +00:00
|
|
|
}
|
2015-03-12 20:50:19 +00:00
|
|
|
pages.add(new CyanogenSettingsPage(mContext, this));
|
2015-01-16 00:04:44 +00:00
|
|
|
pages.add(new FinishPage(mContext, this));
|
|
|
|
return new PageList(pages.toArray(new SetupPage[pages.size()]));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-30 01:36:30 +00:00
|
|
|
@Override
|
|
|
|
public void onReceive(Context context, Intent intent) {
|
|
|
|
if (intent.getAction().equals(TelephonyIntents.ACTION_SIM_STATE_CHANGED)) {
|
2015-04-15 00:28:37 +00:00
|
|
|
showHideDataSimPage();
|
|
|
|
showHideSimMissingPage();
|
2015-02-05 01:13:57 +00:00
|
|
|
showHideMobileDataPage();
|
2016-12-29 16:28:02 +00:00
|
|
|
updateLocalePage();
|
2015-02-13 18:51:10 +00:00
|
|
|
} else if (intent.getAction()
|
2015-10-14 19:44:53 +00:00
|
|
|
.equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
|
2015-05-07 21:05:29 +00:00
|
|
|
showHideMobileDataPage();
|
2016-12-29 16:28:02 +00:00
|
|
|
} else if (intent.getAction()
|
2015-02-05 01:13:57 +00:00
|
|
|
.equals(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED)) {
|
|
|
|
showHideMobileDataPage();
|
2015-02-04 01:02:02 +00:00
|
|
|
} else if (intent.getAction().equals(Intent.ACTION_TIMEZONE_CHANGED) ||
|
|
|
|
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE)) {
|
2015-01-30 01:36:30 +00:00
|
|
|
mTimeZoneSet = true;
|
2015-02-05 01:13:57 +00:00
|
|
|
showHideDateTimePage();
|
2015-02-04 01:02:02 +00:00
|
|
|
} else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED) ||
|
|
|
|
intent.getAction().equals(TelephonyIntents.ACTION_NETWORK_SET_TIME)) {
|
2015-01-30 01:36:30 +00:00
|
|
|
mTimeSet = true;
|
2015-02-05 01:13:57 +00:00
|
|
|
showHideDateTimePage();
|
2015-01-30 01:36:30 +00:00
|
|
|
}
|
2015-02-05 01:13:57 +00:00
|
|
|
}
|
2015-01-30 01:36:30 +00:00
|
|
|
|
2015-02-13 18:51:10 +00:00
|
|
|
|
2015-04-15 00:28:37 +00:00
|
|
|
private void showHideSimMissingPage() {
|
|
|
|
SimCardMissingPage simCardMissingPage =
|
|
|
|
(SimCardMissingPage) getPage(SimCardMissingPage.TAG);
|
2015-09-17 20:48:55 +00:00
|
|
|
if (simCardMissingPage != null) {
|
|
|
|
if (isSimInserted()) {
|
|
|
|
simCardMissingPage.setHidden(true);
|
|
|
|
if (isCurrentPage(simCardMissingPage)) {
|
|
|
|
onNextPage();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
simCardMissingPage.setHidden(false);
|
2015-04-15 00:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showHideDataSimPage() {
|
|
|
|
ChooseDataSimPage chooseDataSimPage =
|
|
|
|
(ChooseDataSimPage) getPage(ChooseDataSimPage.TAG);
|
|
|
|
if (chooseDataSimPage != null) {
|
2015-04-27 20:20:13 +00:00
|
|
|
chooseDataSimPage.setHidden(!allSimsInserted());
|
2015-04-15 00:28:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-05 01:13:57 +00:00
|
|
|
private void showHideMobileDataPage() {
|
|
|
|
MobileDataPage mobileDataPage =
|
|
|
|
(MobileDataPage) getPage(MobileDataPage.TAG);
|
|
|
|
if (mobileDataPage != null) {
|
2015-05-07 21:05:29 +00:00
|
|
|
mobileDataPage.setHidden(!isSimInserted() || mMobileDataEnabled);
|
2015-01-30 01:36:30 +00:00
|
|
|
}
|
2015-02-05 01:13:57 +00:00
|
|
|
}
|
2015-01-30 01:36:30 +00:00
|
|
|
|
2015-02-05 01:13:57 +00:00
|
|
|
private void showHideDateTimePage() {
|
|
|
|
DateTimePage dateTimePage = (DateTimePage) getPage(DateTimePage.TAG);
|
|
|
|
if (dateTimePage != null) {
|
|
|
|
dateTimePage.setHidden(mTimeZoneSet & mTimeSet);
|
2015-01-30 01:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-29 16:28:02 +00:00
|
|
|
private void updateLocalePage() {
|
|
|
|
LocalePage localePage = (LocalePage) getPage(LocalePage.TAG);
|
|
|
|
if (localePage != null) {
|
|
|
|
localePage.simChanged();
|
2016-01-19 02:39:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-30 01:36:30 +00:00
|
|
|
public IntentFilter getIntentFilter() {
|
|
|
|
IntentFilter filter = new IntentFilter();
|
2015-02-05 01:13:57 +00:00
|
|
|
if (SetupWizardUtils.hasTelephony(mContext)) {
|
|
|
|
filter.addAction(TelephonyIntents.ACTION_SIM_STATE_CHANGED);
|
|
|
|
filter.addAction(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
|
|
|
}
|
2015-02-13 18:51:10 +00:00
|
|
|
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
|
2015-01-30 01:36:30 +00:00
|
|
|
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
|
|
|
|
filter.addAction(Intent.ACTION_TIME_CHANGED);
|
2015-02-04 01:02:02 +00:00
|
|
|
filter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIME);
|
|
|
|
filter.addAction(TelephonyIntents.ACTION_NETWORK_SET_TIMEZONE);
|
2015-01-30 01:36:30 +00:00
|
|
|
return filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We only care that one sim is inserted
|
|
|
|
private boolean isSimInserted() {
|
2015-02-05 01:13:57 +00:00
|
|
|
TelephonyManager tm = TelephonyManager.from(mContext);
|
|
|
|
int simSlotCount = tm.getSimCount();
|
|
|
|
for (int i = 0; i < simSlotCount; i++) {
|
2015-06-18 23:21:06 +00:00
|
|
|
int state;
|
|
|
|
try {
|
|
|
|
state = tm.getSimState(i);
|
|
|
|
} catch (IllegalStateException ise) {
|
|
|
|
Log.e(TAG, "Unable to get sim state from TelephonyManager");
|
|
|
|
continue;
|
|
|
|
}
|
2015-01-30 01:36:30 +00:00
|
|
|
if (state != TelephonyManager.SIM_STATE_ABSENT
|
2015-09-17 20:48:55 +00:00
|
|
|
&& state != TelephonyManager.SIM_STATE_UNKNOWN
|
|
|
|
&& state != TelephonyManager.SIM_STATE_NOT_READY) {
|
2015-01-30 01:36:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-05 01:13:57 +00:00
|
|
|
// We only care that each slot has a sim
|
2015-01-30 01:36:30 +00:00
|
|
|
private boolean allSimsInserted() {
|
2015-02-05 01:13:57 +00:00
|
|
|
TelephonyManager tm = TelephonyManager.from(mContext);
|
|
|
|
int simSlotCount = tm.getSimCount();
|
|
|
|
for (int i = 0; i < simSlotCount; i++) {
|
|
|
|
int state = tm.getSimState(i);
|
2015-01-30 01:36:30 +00:00
|
|
|
if (state == TelephonyManager.SIM_STATE_ABSENT) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2015-04-27 20:20:13 +00:00
|
|
|
return simSlotCount == SubscriptionManager.from(mContext).getActiveSubscriptionInfoCount();
|
2015-01-30 01:36:30 +00:00
|
|
|
}
|
|
|
|
|
2015-04-24 02:54:36 +00:00
|
|
|
}
|