Changes for new network setup flow

* Remove mobile data/choose data sim pages
* Rename Wi-Fi setup to network setup
* Switch to the new NetworkProviderSettings which contains
  both Wi-Fi and mobile data setup.

Change-Id: I1c618d629628740e39dbed313d468d1efe971ed7
This commit is contained in:
Michael Bestas
2021-10-09 01:55:56 +03:00
parent 0e9b6ebcbf
commit 334cd1bce7
11 changed files with 19 additions and 1129 deletions

View File

@@ -150,32 +150,6 @@
</intent-filter>
</activity>
<activity android:name=".WifiSetupActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
android:configChanges="mcc|mnc"
android:immersive="true"
android:exported="false"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="org.lineageos.setupwizard.LINEAGE_WIFI_SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".CaptivePortalSetupActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
android:configChanges="mcc|mnc"
android:immersive="true"
android:exported="false"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="org.lineageos.setupwizard.LINEAGE_CAPTIVE_PORTAL_SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".SimMissingActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
@@ -189,7 +163,7 @@
</intent-filter>
</activity>
<activity android:name=".ChooseDataSimActivity"
<activity android:name=".NetworkSetupActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
android:configChanges="mcc|mnc"
@@ -197,12 +171,12 @@
android:exported="false"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="org.lineageos.setupwizard.LINEAGE_CHOOSE_DATA_SIM" />
<action android:name="org.lineageos.setupwizard.LINEAGE_NETWORK_SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".MobileDataActivity"
<activity android:name=".CaptivePortalSetupActivity"
android:label="@string/activity_label_empty"
android:excludeFromRecents="true"
android:configChanges="mcc|mnc"
@@ -210,7 +184,7 @@
android:exported="false"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="org.lineageos.setupwizard.LINEAGE_ENABLE_MOBILE_DATA" />
<action android:name="org.lineageos.setupwizard.LINEAGE_CAPTIVE_PORTAL_SETUP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

View File

@@ -1,76 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod Project
Copyright (C) 2017-2021 The LineageOS 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.
-->
<com.google.android.setupdesign.GlifLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/setup_wizard_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/SudContentFrame">
<FrameLayout
android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/page_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/SudDescription.Glif"
android:text="@string/choose_data_sim_summary" />
<include layout="@layout/divider" />
</LinearLayout>
</ScrollView>
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp"
android:layout_gravity="top"
android:visibility="gone" />
</FrameLayout>
<org.lineageos.setupwizard.NavigationLayout
android:id="@+id/navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</com.google.android.setupdesign.GlifLayout>

View File

@@ -1,51 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 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.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sim_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_margin_left"
android:paddingRight="@dimen/data_switch_margin_right"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<ImageView
android:id="@+id/signal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_signal_0" />
<TextView
android:id="@+id/sim_title"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14sp"
android:layout_marginLeft="@dimen/carrier_text_margin_left"
android:maxLines="4" />
<CheckBox
android:id="@+id/enable_check"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:duplicateParentState="true"
android:clickable="false"/>
</LinearLayout>

View File

@@ -1,116 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2013 The CyanogenMod Project
Copyright (C) 2017-2021 The LineageOS 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.
-->
<com.google.android.setupdesign.GlifLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/setup_wizard_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/SudContentFrame">
<ProgressBar
android:id="@+id/progress"
style="@style/SudFourColorIndeterminateProgressBar"
android:indeterminateOnly="true"
android:layout_width="match_parent"
android:layout_height="8dp"
android:visibility="gone" />
<FrameLayout
android:id="@+id/page"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:id="@+id/page_view"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/mobile_data_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/enable_mobile_data_summary"
style="@style/SudDescription.Glif" />
<include layout="@layout/divider" />
<LinearLayout
android:id="@+id/data"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_margin_left"
android:paddingRight="@dimen/data_switch_margin_right"
android:background="?android:attr/selectableItemBackground"
android:clickable="true">
<ImageView
android:id="@+id/signal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_signal_0" />
<TextView
android:id="@+id/enable_data_title"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textSize="14sp"
android:layout_marginLeft="@dimen/carrier_text_margin_left"
android:text="@string/setup_mobile_data_no_service"
android:maxLines="4" />
<Switch
android:id="@+id/data_switch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:duplicateParentState="true"
android:clickable="false"
android:textOff="@string/no"
android:textOn="@string/yes"
style="@style/SudSwitchStyle" />
</LinearLayout>
<include layout="@layout/divider" />
</LinearLayout>
</ScrollView>
</FrameLayout>
<org.lineageos.setupwizard.NavigationLayout
android:id="@+id/navigation_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</com.google.android.setupdesign.GlifLayout>

View File

@@ -2,7 +2,7 @@
<!--
Copyright (C) 2016 The CyanogenMod Project
Copyright (C) 2017 The LineageOS Project
Copyright (C) 2017-2021 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -32,23 +32,14 @@
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_DATETIME;end" id="datetime">
<result wizard:action="wifi_setup" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_WIFI_SETUP;end" id="wifi_setup">
<result wizard:action="sim_missing" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_SIM_MISSING;end" id="sim_missing">
<result wizard:resultCode="1" wizard:action="location_settings" wizard:name="skip_sim" />
<result wizard:action="choose_data_sim" />
<result wizard:action="network_setup" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_CHOOSE_DATA_SIM;end" id="choose_data_sim">
<result wizard:action="enable_mobile_data" />
</WizardAction>
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_ENABLE_MOBILE_DATA;end" id="enable_mobile_data">
<WizardAction wizard:uri="intent:#Intent;action=org.lineageos.setupwizard.LINEAGE_NETWORK_SETUP;end" id="network_setup">
<result wizard:action="location_settings" />
</WizardAction>

View File

@@ -1,483 +0,0 @@
/*
* Copyright (C) 2016 The CyanogenMod Project
* Copyright (C) 2017-2018,2020 The LineageOS 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 org.lineageos.setupwizard;
import static org.lineageos.setupwizard.SetupWizardApp.LOGV;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.util.Log;
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 org.lineageos.setupwizard.util.PhoneMonitor;
import org.lineageos.setupwizard.util.SetupWizardUtils;
import java.util.List;
public class ChooseDataSimActivity extends BaseSetupWizardActivity {
public static final String TAG = ChooseDataSimActivity.class.getSimpleName();
private ViewGroup mPageView;
private ProgressBar mProgressBar;
private SparseArray<TextView> mNameViews;
private SparseArray<ImageView> mSignalViews;
private SparseArray<CheckBox> mCheckBoxes;
private SparseArray<View> mRows;
private SparseArray<SubscriptionInfo> mSubInfoRecords;
private SparseArray<SignalStrength> mSignalStrengths;
private SparseArray<ServiceState> mServiceStates;
private boolean mIsAttached = false;
private boolean mRadioReady = false;
private PhoneMonitor mPhoneMonitor;
private boolean mDisabledForSwitch = false;
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = () -> {
// If we timeout out waiting for the radio, Oh well.
if (!mRadioReady) {
mRadioReady = true;
checkForRadioReady();
}
};
private final View.OnClickListener mSetDataSimClickListener = view -> {
SubscriptionInfo subInfoRecord = (SubscriptionInfo) view.getTag();
if (subInfoRecord != null) {
changeDataSub(subInfoRecord);
}
};
private final PhoneMonitor.SubscriptionStateListener mSubscriptionStateListener =
new PhoneMonitor.SubscriptionStateListener() {
@Override
public void onServiceStateChanged(int subId, ServiceState serviceState) {
if (LOGV) {
Log.v(TAG, "onServiceStateChanged{" +
"subId='" + subId + '\'' +
", serviceState=" + serviceState.toString() +
'}');
}
SubscriptionInfo subInfoRecord =
mPhoneMonitor.getActiveSubscriptionInfo(subId);
mRadioReady = SetupWizardUtils.isRadioReady(
ChooseDataSimActivity.this, serviceState);
checkForRadioReady();
mServiceStates.put(subInfoRecord.getSimSlotIndex(), serviceState);
updateSignalStrength(subInfoRecord);
}
@Override
public void onDataConnectionStateChanged(int subId, int state, int networkType) {
if (LOGV) {
Log.v(TAG, "onDataConnectionStateChanged{" +
"subId='" + subId + '\'' +
", state=" + state +
'}');
}
onDefaultDataSubscriptionChanged(subId);
}
@Override
public void onDefaultDataSubscriptionChanged(int subId) {
if (LOGV) {
Log.v(TAG, "onDefaultDataSubscriptionChanged{" +
"subId='" + subId + '\'' +
'}');
}
final int currentDataSubId = SubscriptionManager.getDefaultDataSubscriptionId();
if (currentDataSubId != subId) {
updateCurrentDataSub();
hideProgress();
enableViews(true);
}
checkSimChangingState(currentDataSubId, subId);
}
@Override
public void onDefaultDataSubscriptionChangeRequested(int currentSubId,
int newSubId) {
if (LOGV) {
Log.v(TAG, "onDefaultDataSubscriptionChangeRequested{" +
"currentSubId='" + currentSubId + '\'' +
", newSubId=" + newSubId +
'}');
}
checkSimChangingState(currentSubId, newSubId);
}
@Override
public void onSignalStrengthsChanged(int subId, SignalStrength signalStrength) {
if (LOGV) {
Log.v(TAG, "onSignalStrengthsChanged{" +
"subId='" + subId + '\'' +
", signalStrength=" + signalStrength.toString() +
'}');
}
SubscriptionInfo subInfoRecord =
mPhoneMonitor.getActiveSubscriptionInfo(subId);
mSignalStrengths.put(subInfoRecord.getSimSlotIndex(), signalStrength);
updateSignalStrength(subInfoRecord);
}
@Override
public void onSimStateChanged(int subId, int simState) {
if (LOGV) {
Log.v(TAG, "onSimStateChanged{" +
"subId='" + subId + '\'' +
", simState=" + simState +
'}');
}
updateSignalStrengths();
updateCurrentDataSub();
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setNextText(R.string.next);
mPhoneMonitor = PhoneMonitor.getInstance();
mPageView = (ViewGroup) findViewById(R.id.page_view);
mProgressBar = (ProgressBar) findViewById(R.id.progress);
List<SubscriptionInfo> subInfoRecords = mPhoneMonitor.getActiveSubscriptionInfoList();
int simCount =
subInfoRecords != null ? subInfoRecords.size() : 0;
mSubInfoRecords = new SparseArray<>(simCount);
for (SubscriptionInfo subInfoRecord : subInfoRecords) {
mSubInfoRecords.put(subInfoRecord.getSimSlotIndex(), subInfoRecord);
updateSignalStrength(subInfoRecord);
}
mNameViews = new SparseArray<>(simCount);
mSignalViews = new SparseArray<>(simCount);
mCheckBoxes = new SparseArray<>(simCount);
mRows = new SparseArray<>(simCount);
mServiceStates = new SparseArray<>(simCount);
mSignalStrengths = new SparseArray<>(simCount);
LayoutInflater inflater = LayoutInflater.from(this);
for (int i = 0; i < simCount; i++) {
View simRow = inflater.inflate(R.layout.data_sim_row, null);
mPageView.addView(simRow);
SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i);
simRow.setTag(subInfoRecord);
simRow.setOnClickListener(mSetDataSimClickListener);
int slot = subInfoRecord.getSimSlotIndex();
mNameViews.put(slot, (TextView) simRow.findViewById(R.id.sim_title));
mSignalViews.put(slot, (ImageView) simRow.findViewById(R.id.signal));
mCheckBoxes.put(slot, (CheckBox) simRow.findViewById(R.id.enable_check));
mRows.put(slot, simRow);
mPageView.addView(inflater.inflate(R.layout.divider, null));
}
updateSignalStrengths();
updateCurrentDataSub();
}
@Override
public void onPause() {
super.onPause();
mIsAttached = false;
mPhoneMonitor.removeListener(mSubscriptionStateListener);
}
@Override
public void onResume() {
super.onResume();
mIsAttached = true;
mPhoneMonitor.addListener(mSubscriptionStateListener);
mRadioReady = SetupWizardUtils.isRadioReady(this, null);
updateSignalStrengths();
updateCurrentDataSub();
checkForRadioReady();
if (mRadioReady) {
final int currentDataSub = SubscriptionManager.getDefaultDataSubscriptionId();
checkSimChangingState(currentDataSub, currentDataSub);
}
}
private void checkForRadioReady() {
if (mRadioReady) {
mHandler.removeCallbacks(mRadioReadyRunnable);
showPage();
final int currentDataSub = SubscriptionManager.getDefaultDataSubscriptionId();
checkSimChangingState(currentDataSub, currentDataSub);
return;
} else {
enableViews(false);
showProgress();
if (!mHandler.hasCallbacks(mRadioReadyRunnable)) {
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
}
}
private void showPage() {
mPageView.setVisibility(View.VISIBLE);
if (!mPageView.isShown()) {
mPageView.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.translucent_enter));
}
}
private void showProgress() {
if (!mProgressBar.isShown()) {
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.translucent_enter));
}
}
private void hideProgress() {
if (mProgressBar.isShown()) {
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.translucent_exit));
mProgressBar.setVisibility(View.INVISIBLE);
}
}
private void updateSignalStrengths() {
if (mIsAttached) {
for (int i = 0; i < mSubInfoRecords.size(); i++) {
updateSignalStrength(mSubInfoRecords.valueAt(i));
}
}
}
private void changeDataSub(SubscriptionInfo subInfoRecord) {
final int currentDataSub = SubscriptionManager.getDefaultDataSubscriptionId();
final int requestedDataSub = subInfoRecord.getSubscriptionId();
if (LOGV) {
Log.v(TAG, "changeDataSub{" +
"currentDataSub='" + currentDataSub + '\'' +
", requestedDataSub=" + requestedDataSub +
'}');
}
if (currentDataSub != requestedDataSub) {
mPhoneMonitor.changeDataSub(requestedDataSub);
setDataSubChecked(subInfoRecord);
checkSimChangingState(currentDataSub, requestedDataSub);
}
}
private void checkSimChangingState(int currentDataSubId, int changingToDataSubId) {
if (LOGV) {
Log.v(TAG, "checkSimChangingState{" +
"currentDataSubId='" + currentDataSubId + '\'' +
"changingToDataSubId='" + changingToDataSubId + '\'' +
"mIsAttached='" + mIsAttached + '\'' +
", mRadioReady=" + mRadioReady +
'}');
}
if (mIsAttached && mRadioReady) {
if (currentDataSubId != changingToDataSubId) {
showProgress();
enableViews(false);
} else {
hideProgress();
enableViews(true);
}
}
}
private void setDataSubChecked(SubscriptionInfo subInfoRecord) {
if (mIsAttached) {
for (int i = 0; i < mCheckBoxes.size(); i++) {
int key = mCheckBoxes.keyAt(i);
mCheckBoxes.get(key).setChecked(subInfoRecord.getSimSlotIndex() == key);
}
}
}
private void updateCurrentDataSub() {
if (mIsAttached) {
for (int i = 0; i < mSubInfoRecords.size(); i++) {
SubscriptionInfo subInfoRecord = mSubInfoRecords.valueAt(i);
int slot = subInfoRecord.getSimSlotIndex();
mCheckBoxes.get(slot).setChecked(SubscriptionManager.getDefaultDataSubscriptionId()
== subInfoRecord.getSubscriptionId());
if (LOGV) {
Log.v(TAG, "updateCurrentDataSub{" +
"currentDataSubId='" + SubscriptionManager
.getDefaultDataSubscriptionId() + '\'' +
"subInfoRecord.getSubscriptionId()='" +
subInfoRecord.getSubscriptionId() +
'}');
}
}
}
}
private void enableViews(boolean enabled) {
mDisabledForSwitch = !enabled;
enableRows(enabled);
setNextAllowed(enabled);
}
private void enableRows(boolean enabled) {
for (int i = 0; i < mRows.size(); i++) {
final View v = mRows.get(mRows.keyAt(i));
v.setEnabled(enabled);
final SubscriptionInfo subInfoRecord = (SubscriptionInfo) v.getTag();
if (subInfoRecord != null) {
updateCarrierText(subInfoRecord);
}
}
}
private void updateCarrierText(SubscriptionInfo subInfoRecord) {
if (mIsAttached) {
String name = mPhoneMonitor.getSimOperatorName(subInfoRecord.getSubscriptionId());
if (TextUtils.isEmpty(name)) {
name = mPhoneMonitor.getNetworkOperatorName(subInfoRecord.getSubscriptionId());
}
ServiceState serviceState = mServiceStates.get(subInfoRecord.getSimSlotIndex());
final int slot = subInfoRecord.getSimSlotIndex();
final View v = mRows.get(slot);
if (TextUtils.isEmpty(name)) {
if (serviceState != null && serviceState.isEmergencyOnly()) {
name = getString(R.string.setup_mobile_data_emergency_only);
} else {
name = getString(R.string.setup_mobile_data_no_service);
}
if (v != null) {
v.setEnabled(false);
}
} else {
if (v != null && !mDisabledForSwitch) {
v.setEnabled(true);
}
}
String formattedName =
getString(R.string.data_sim_name,
slot + 1, name);
mNameViews.get(slot).setText(formattedName);
}
}
private void updateSignalStrength(SubscriptionInfo subInfoRecord) {
if (mIsAttached) {
ImageView signalView = mSignalViews.get(subInfoRecord.getSimSlotIndex());
SignalStrength signalStrength = mSignalStrengths.get(subInfoRecord.getSimSlotIndex());
if (LOGV) {
Log.v(TAG, "updateSignalStrength{" +
"signalStrength='" + signalStrength + '\'' +
"signalStrengthLevel='" + ((signalStrength != null) ?
signalStrength.getLevel() : "null") + '\'' +
", subInfoRecord.getSimSlotIndex() =" + subInfoRecord.getSimSlotIndex() +
'}');
}
if (!hasService(subInfoRecord)) {
signalView.setImageResource(R.drawable.ic_signal_no_signal);
} else {
if (signalStrength != null) {
int resId;
switch (signalStrength.getLevel()) {
case 4:
resId = R.drawable.ic_signal_4;
break;
case 3:
resId = R.drawable.ic_signal_3;
break;
case 2:
resId = R.drawable.ic_signal_2;
break;
case 1:
resId = R.drawable.ic_signal_1;
break;
default:
resId = R.drawable.ic_signal_0;
break;
}
signalView.setImageResource(resId);
}
}
updateCarrierText(subInfoRecord);
}
}
private boolean hasService(SubscriptionInfo subInfoRecord) {
boolean retVal;
ServiceState serviceState = mServiceStates.get(subInfoRecord.getSimSlotIndex());
if (serviceState == null) {
serviceState = mPhoneMonitor
.getServiceStateForSubscriber(subInfoRecord.getSubscriptionId());
mServiceStates.put(subInfoRecord.getSimSlotIndex(), serviceState);
}
if (serviceState != null) {
if (LOGV) {
Log.v(TAG, "hasService{" +
"serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState()
+ '\''
+ "serviceState.getVoiceRegState()='" + serviceState.getVoiceRegState()
+ '\''
+ ", subInfoRecord.getSimSlotIndex() =" + subInfoRecord.getSimSlotIndex()
+ '}');
}
// Consider the device to be in service if either voice or data service is available.
// Some SIM cards are marketed as data-only and do not support voice service, and on
// these SIM cards, we want to show signal bars for data service as well as the "no
// service" or "emergency calls only" text that indicates that voice is not available.
switch (serviceState.getVoiceRegState()) {
case ServiceState.STATE_POWER_OFF:
retVal = false;
break;
case ServiceState.STATE_OUT_OF_SERVICE:
case ServiceState.STATE_EMERGENCY_ONLY:
retVal = serviceState.getDataRegState() == ServiceState.STATE_IN_SERVICE;
break;
default:
retVal = true;
}
} else {
retVal = false;
}
return retVal;
}
@Override
protected int getLayoutResId() {
return R.layout.choose_data_sim_page;
}
@Override
protected int getTitleResId() {
return R.string.setup_choose_data_sim;
}
@Override
protected int getIconResId() {
return R.drawable.ic_sim;
}
}

View File

@@ -1,321 +0,0 @@
/*
* Copyright (C) 2016 The CyanogenMod Project
* Copyright (C) 2017-2018,2020 The LineageOS 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 org.lineageos.setupwizard;
import static org.lineageos.setupwizard.SetupWizardApp.LOGV;
import android.os.Bundle;
import android.os.Handler;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Switch;
import android.widget.TextView;
import org.lineageos.setupwizard.util.NetworkMonitor;
import org.lineageos.setupwizard.util.PhoneMonitor;
import org.lineageos.setupwizard.util.SetupWizardUtils;
public class MobileDataActivity extends BaseSetupWizardActivity {
public static final String TAG = MobileDataActivity.class.getSimpleName();
private static final int DC_READY_TIMEOUT = 20 * 1000;
private ProgressBar mProgressBar;
private View mEnableDataRow;
private Switch mEnableMobileData;
private ImageView mSignalView;
private TextView mNameView;
private TelephonyManager mPhone;
private SignalStrength mSignalStrength;
private ServiceState mServiceState;
private PhoneMonitor mPhoneMonitor;
private NetworkMonitor mNetworkMonitor;
private boolean mIsAttached = false;
private final Handler mHandler = new Handler();
private final Runnable mRadioReadyRunnable = this::hideWaitForRadio;
private final Runnable mDataConnectionReadyRunnable = this::onDataStateReady;
private final PhoneMonitor.SubscriptionStateListener mSubscriptionStateListener =
new PhoneMonitor.SubscriptionStateListener() {
@Override
public void onServiceStateChanged(int subId, ServiceState serviceState) {
if (LOGV) {
Log.v(TAG, "onServiceStateChanged{" +
"subId='" + subId + '\'' +
", serviceState=" + serviceState.toString() +
'}');
}
if (SetupWizardUtils.isRadioReady(MobileDataActivity.this, serviceState)) {
hideWaitForRadio();
}
mServiceState = serviceState;
updateSignalStrength();
}
@Override
public void onDataConnectionStateChanged(int subId, int state, int networkType) {
if (LOGV) {
Log.v(TAG, "onDataConnectionStateChanged{" +
"subId='" + subId + '\'' +
", state=" + state +
'}');
}
if (state == TelephonyManager.DATA_CONNECTED) {
onDataStateReady();
}
}
@Override
public void onDefaultDataSubscriptionChanged(int subId) {
}
@Override
public void onDefaultDataSubscriptionChangeRequested(int currentSubId,
int newSubId) {
}
@Override
public void onSignalStrengthsChanged(int subId, SignalStrength signalStrength) {
if (LOGV) {
Log.v(TAG, "onSignalStrengthsChanged{" +
"subId='" + subId + '\'' +
", signalStrength=" + signalStrength.toString() +
'}');
}
mSignalStrength = signalStrength;
updateSignalStrength();
}
@Override
public void onSimStateChanged(int subId, int simState) {
if (LOGV) {
Log.v(TAG, "onSimStateChanged{" +
"subId='" + subId + '\'' +
", simState=" + simState +
'}');
}
}
};
private final View.OnClickListener mEnableDataClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !mEnableMobileData.isChecked();
SetupWizardUtils.setMobileDataEnabled(MobileDataActivity.this, checked);
mEnableMobileData.setChecked(checked);
if (checked && !mNetworkMonitor.isWifiConnected()) {
waitForData();
} else {
onDataStateReady();
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mPhoneMonitor = PhoneMonitor.getInstance();
mNetworkMonitor = NetworkMonitor.getInstance();
setNextText(R.string.next);
mProgressBar = (ProgressBar) findViewById(R.id.progress);
mEnableDataRow = findViewById(R.id.data);
mEnableDataRow.setOnClickListener(mEnableDataClickListener);
mEnableMobileData = (Switch) findViewById(R.id.data_switch);
mSignalView = (ImageView) findViewById(R.id.signal);
mNameView = (TextView) findViewById(R.id.enable_data_title);
updateDataConnectionStatus();
updateSignalStrength();
}
@Override
public void onResume() {
super.onResume();
mIsAttached = true;
mPhone = getSystemService(TelephonyManager.class);
mPhoneMonitor.addListener(mSubscriptionStateListener);
updateDataConnectionStatus();
updateSignalStrength();
if (SetupWizardUtils.isRadioReady(this, null)) {
hideWaitForRadio();
} else {
mHandler.postDelayed(mRadioReadyRunnable, SetupWizardApp.RADIO_READY_TIMEOUT);
}
}
@Override
public void onPause() {
super.onPause();
mIsAttached = false;
mPhoneMonitor.removeListener(mSubscriptionStateListener);
}
private void hideWaitForRadio() {
if (mProgressBar.isShown()) {
mHandler.removeCallbacks(mRadioReadyRunnable);
// Something else, like data enablement, may have grabbed
// the "hold" status. Kill it only if "Next" is active
if (isNextAllowed()) {
mProgressBar.setVisibility(View.INVISIBLE);
}
}
}
private void waitForData() {
if (!mProgressBar.isShown()) {
mProgressBar.setVisibility(View.VISIBLE);
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.translucent_enter));
mEnableDataRow.setEnabled(false);
setNextAllowed(false);
mHandler.postDelayed(mDataConnectionReadyRunnable, DC_READY_TIMEOUT);
}
}
private void onDataStateReady() {
mHandler.removeCallbacks(mDataConnectionReadyRunnable);
if ((mProgressBar.isShown()) ||
!isNextAllowed()) {
mProgressBar.startAnimation(
AnimationUtils.loadAnimation(this, R.anim.translucent_exit));
mProgressBar.setVisibility(View.INVISIBLE);
mEnableDataRow.setEnabled(true);
setNextAllowed(true);
}
}
private void updateCarrierText() {
if (mIsAttached) {
String name = mPhone.getSimOperatorName(getDefaultSubscriptionId());
if (TextUtils.isEmpty(name)) {
name = mPhone.getNetworkOperatorName(getDefaultSubscriptionId());
}
if (TextUtils.isEmpty(name)) {
if (mServiceState != null && mServiceState.isEmergencyOnly()) {
name = getString(R.string.setup_mobile_data_emergency_only);
} else {
name = getString(R.string.setup_mobile_data_no_service);
}
}
mNameView.setText(name);
}
}
private void updateSignalStrength() {
if (mIsAttached) {
if (LOGV) {
Log.v(TAG, "updateSignalStrength{" +
"signalStrength='" + mSignalStrength + '\'' +
"signalStrengthLevel='" + ((mSignalStrength != null) ?
mSignalStrength.getLevel() : "null") + '\'' +
'}');
}
if (!hasService()) {
mSignalView.setImageResource(R.drawable.ic_signal_no_signal);
} else {
if (mSignalStrength != null) {
int resId;
switch (mSignalStrength.getLevel()) {
case 4:
resId = R.drawable.ic_signal_4;
break;
case 3:
resId = R.drawable.ic_signal_3;
break;
case 2:
resId = R.drawable.ic_signal_2;
break;
case 1:
resId = R.drawable.ic_signal_1;
break;
default:
resId = R.drawable.ic_signal_0;
break;
}
mSignalView.setImageResource(resId);
}
}
updateCarrierText();
}
}
private void updateDataConnectionStatus() {
mEnableMobileData.setChecked(SetupWizardUtils.isMobileDataEnabled(this));
}
private boolean hasService() {
boolean retVal;
if (mServiceState == null) {
mServiceState = TelephonyManager.from(this)
.getServiceStateForSubscriber(getDefaultSubscriptionId());
}
if (mServiceState != null) {
// Consider the device to be in service if either voice or data service is available.
// Some SIM cards are marketed as data-only and do not support voice service, and on
// these SIM cards, we want to show signal bars for data service as well as the "no
// service" or "emergency calls only" text that indicates that voice is not available.
switch (mServiceState.getVoiceRegState()) {
case ServiceState.STATE_POWER_OFF:
retVal = false;
break;
case ServiceState.STATE_OUT_OF_SERVICE:
case ServiceState.STATE_EMERGENCY_ONLY:
retVal = mServiceState.getDataRegState() == ServiceState.STATE_IN_SERVICE;
break;
default:
retVal = true;
}
} else {
retVal = false;
}
return retVal;
}
@Override
protected int getLayoutResId() {
return R.layout.mobile_data_settings;
}
@Override
protected int getTitleResId() {
return R.string.setup_mobile_data;
}
@Override
protected int getIconResId() {
return R.drawable.ic_mobile_data;
}
private int getDefaultSubscriptionId() {
return SubscriptionManager.getDefaultSubscriptionId();
}
}

View File

@@ -17,12 +17,12 @@
package org.lineageos.setupwizard;
import static org.lineageos.setupwizard.SetupWizardApp.ACTION_SETUP_WIFI;
import static org.lineageos.setupwizard.SetupWizardApp.ACTION_SETUP_NETWORK;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_ENABLE_NEXT_ON_CONNECT;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_PREFS_SET_BACK_TEXT;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_PREFS_SHOW_BUTTON_BAR;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_PREFS_SHOW_SKIP;
import static org.lineageos.setupwizard.SetupWizardApp.REQUEST_CODE_SETUP_WIFI;
import static org.lineageos.setupwizard.SetupWizardApp.REQUEST_CODE_SETUP_NETWORK;
import static org.lineageos.setupwizard.SetupWizardApp.EXTRA_PREFS_SHOW_SKIP_TV;
import android.content.Intent;
@@ -31,14 +31,14 @@ import com.google.android.setupcompat.util.WizardManagerHelper;
import org.lineageos.setupwizard.util.SetupWizardUtils;
public class WifiSetupActivity extends WrapperSubBaseActivity {
public class NetworkSetupActivity extends WrapperSubBaseActivity {
public static final String TAG = WifiSetupActivity.class.getSimpleName();
public static final String TAG = NetworkSetupActivity.class.getSimpleName();
@Override
protected void onStartSubactivity() {
tryEnablingWifi();
Intent intent = new Intent(ACTION_SETUP_WIFI);
Intent intent = new Intent(ACTION_SETUP_NETWORK);
if (SetupWizardUtils.hasLeanback(this)) {
intent.setComponent(SetupWizardUtils.sTvWifiSetupSettingsActivity);
}
@@ -48,6 +48,6 @@ public class WifiSetupActivity extends WrapperSubBaseActivity {
intent.putExtra(EXTRA_PREFS_SHOW_SKIP_TV, true);
intent.putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null);
intent.putExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, true);
startSubactivity(intent, REQUEST_CODE_SETUP_WIFI);
startSubactivity(intent, REQUEST_CODE_SETUP_NETWORK);
}
}

View File

@@ -38,7 +38,7 @@ public class SetupWizardApp extends Application {
public static final String ACTION_SETUP_COMPLETE =
"org.lineageos.setupwizard.LINEAGE_SETUP_COMPLETE";
public static final String ACTION_FINISHED = "org.lineageos.setupwizard.SETUP_FINISHED";
public static final String ACTION_SETUP_WIFI = "android.net.wifi.SETUP_WIFI_NETWORK";
public static final String ACTION_SETUP_NETWORK = "android.settings.NETWORK_PROVIDER_SETUP";
public static final String ACTION_SETUP_BIOMETRIC = "android.settings.BIOMETRIC_ENROLL";
public static final String ACTION_SETUP_LOCKSCREEN = "com.android.settings.SETUP_LOCK_SCREEN";
public static final String ACTION_RESTORE_FROM_BACKUP =
@@ -65,7 +65,7 @@ public class SetupWizardApp extends Application {
public static final String ENABLE_RECOVERY_UPDATE = "enable_recovery_update";
public static final String UPDATE_RECOVERY_PROP = "persist.vendor.recovery_update";
public static final int REQUEST_CODE_SETUP_WIFI = 0;
public static final int REQUEST_CODE_SETUP_NETWORK = 0;
public static final int REQUEST_CODE_SETUP_CAPTIVE_PORTAL = 4;
public static final int REQUEST_CODE_SETUP_BLUETOOTH = 5;
public static final int REQUEST_CODE_SETUP_BIOMETRIC = 7;

View File

@@ -23,7 +23,6 @@ import android.widget.ImageView;
import com.google.android.setupcompat.util.ResultCodes;
import org.lineageos.setupwizard.util.PhoneMonitor;
import org.lineageos.setupwizard.util.SetupWizardUtils;
public class SimMissingActivity extends BaseSetupWizardActivity {
@@ -58,24 +57,6 @@ public class SimMissingActivity extends BaseSetupWizardActivity {
}
}
@Override
protected void onResume() {
super.onResume();
SetupWizardUtils.enableComponent(this, ChooseDataSimActivity.class);
SetupWizardUtils.enableComponent(this, MobileDataActivity.class);
}
@Override
public void onNavigateNext() {
if (mPhoneMonitor.simMissing()) {
SetupWizardUtils.disableComponent(this, ChooseDataSimActivity.class);
SetupWizardUtils.disableComponent(this, MobileDataActivity.class);
} else if (!mPhoneMonitor.isMultiSimDevice() || mPhoneMonitor.singleSimInserted()) {
SetupWizardUtils.disableComponent(this, ChooseDataSimActivity.class);
}
super.onNavigateNext();
}
@Override
protected int getLayoutResId() {
return R.layout.sim_missing_page;

View File

@@ -55,11 +55,9 @@ import android.util.Log;
import org.lineageos.internal.util.PackageManagerUtils;
import org.lineageos.setupwizard.BiometricActivity;
import org.lineageos.setupwizard.BluetoothSetupActivity;
import org.lineageos.setupwizard.ChooseDataSimActivity;
import org.lineageos.setupwizard.MobileDataActivity;
import org.lineageos.setupwizard.NetworkSetupActivity;
import org.lineageos.setupwizard.SetupWizardApp;
import org.lineageos.setupwizard.SimMissingActivity;
import org.lineageos.setupwizard.WifiSetupActivity;
import org.lineageos.setupwizard.wizardmanager.WizardManager;
import java.io.File;
@@ -296,18 +294,11 @@ public class SetupWizardUtils {
if (!hasBiometric(context)) {
disableComponent(context, BiometricActivity.class);
}
if (!hasTelephony(context)) {
disableComponent(context, MobileDataActivity.class);
disableComponent(context, SimMissingActivity.class);
disableComponent(context, ChooseDataSimActivity.class);
} else if (!simMissing()) {
if (!hasTelephony(context) || !simMissing()) {
disableComponent(context, SimMissingActivity.class);
}
if (!isMultiSimDevice() || singleSimInserted()) {
disableComponent(context, ChooseDataSimActivity.class);
}
if (!hasWifi(context) || isEthernetConnected(context)) {
disableComponent(context, WifiSetupActivity.class);
if ((!hasWifi(context) && !hasTelephony(context)) || isEthernetConnected(context)) {
disableComponent(context, NetworkSetupActivity.class);
}
}