Remove NetworkProviderSimsCategoryController
Which no real logic in it, just a proxy of NetworkProviderSimListController. Bug: 302628642 Test: manually - on MobileNetworkListFragment Test: robo test Change-Id: I4785ac9509f92f5a778e1bda1f8da12e2880589e
This commit is contained in:
@@ -19,26 +19,19 @@ package com.android.settings.network;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.os.UserManager;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class MobileNetworkListFragment extends DashboardFragment {
|
||||
private static final String LOG_TAG = "NetworkListFragment";
|
||||
|
||||
static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
||||
private static final String KEY_ADD_SIM = "add_sim";
|
||||
|
||||
@Override
|
||||
@@ -68,34 +61,8 @@ public class MobileNetworkListFragment extends DashboardFragment {
|
||||
return SettingsEnums.MOBILE_NETWORK_LIST;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
if (!SubscriptionUtil.isSimHardwareVisible(getContext())) {
|
||||
finish();
|
||||
return controllers;
|
||||
}
|
||||
|
||||
NetworkProviderSimsCategoryController simCategoryPrefCtrl =
|
||||
new NetworkProviderSimsCategoryController(context, KEY_PREFERENCE_CATEGORY_SIM,
|
||||
getSettingsLifecycle(), this);
|
||||
controllers.add(simCategoryPrefCtrl);
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
|
||||
boolean enabled) {
|
||||
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.network_provider_sims_list;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
new BaseSearchIndexProvider(R.xml.network_provider_sims_list) {
|
||||
|
||||
@Override
|
||||
protected boolean isPageSearchEnabled(Context context) {
|
||||
|
||||
@@ -16,69 +16,60 @@
|
||||
|
||||
package com.android.settings.network;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.util.ArrayMap;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.mobile.dataservice.SubscriptionInfoEntity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class NetworkProviderSimListController extends AbstractPreferenceController implements
|
||||
LifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
||||
public class NetworkProviderSimListController extends BasePreferenceController implements
|
||||
DefaultLifecycleObserver, MobileNetworkRepository.MobileNetworkCallback,
|
||||
DefaultSubscriptionReceiver.DefaultSubscriptionListener {
|
||||
private static final String TAG = "NetworkProviderSimListCtrl";
|
||||
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
||||
private static final String KEY_PREFERENCE_SIM = "provider_model_sim_list";
|
||||
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
private final SubscriptionManager mSubscriptionManager;
|
||||
@Nullable
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
private Map<Integer, RestrictedPreference> mPreferences;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private MobileNetworkRepository mMobileNetworkRepository;
|
||||
private final MobileNetworkRepository mMobileNetworkRepository;
|
||||
private List<SubscriptionInfoEntity> mSubInfoEntityList = new ArrayList<>();
|
||||
private DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||
private final DefaultSubscriptionReceiver mDataSubscriptionChangedReceiver;
|
||||
|
||||
public NetworkProviderSimListController(Context context, Lifecycle lifecycle,
|
||||
LifecycleOwner lifecycleOwner) {
|
||||
super(context);
|
||||
public NetworkProviderSimListController(Context context, String preferenceKey) {
|
||||
super(context, preferenceKey);
|
||||
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
|
||||
mPreferences = new ArrayMap<>();
|
||||
mLifecycleOwner = lifecycleOwner;
|
||||
mMobileNetworkRepository = MobileNetworkRepository.getInstance(context);
|
||||
mDataSubscriptionChangedReceiver = new DefaultSubscriptionReceiver(context, this);
|
||||
lifecycle.addObserver(this);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_RESUME)
|
||||
public void onResume() {
|
||||
mMobileNetworkRepository.addRegister(mLifecycleOwner, this,
|
||||
@Override
|
||||
public void onResume(@NonNull LifecycleOwner owner) {
|
||||
mMobileNetworkRepository.addRegister(owner, this,
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
mMobileNetworkRepository.updateEntity();
|
||||
mDataSubscriptionChangedReceiver.registerReceiver();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_PAUSE)
|
||||
public void onPause() {
|
||||
@Override
|
||||
public void onPause(@NonNull LifecycleOwner owner) {
|
||||
mMobileNetworkRepository.removeRegister(this);
|
||||
mDataSubscriptionChangedReceiver.unRegisterReceiver();
|
||||
}
|
||||
@@ -86,7 +77,7 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_SIM);
|
||||
mPreferenceCategory = screen.findPreference(getPreferenceKey());
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -154,31 +145,22 @@ public class NetworkProviderSimListController extends AbstractPreferenceControll
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
if (!getAvailablePhysicalSubscriptions().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
public int getAvailabilityStatus() {
|
||||
return getAvailablePhysicalSubscriptions().isEmpty()
|
||||
? CONDITIONALLY_UNAVAILABLE : AVAILABLE;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected List<SubscriptionInfoEntity> getAvailablePhysicalSubscriptions() {
|
||||
List<SubscriptionInfoEntity> subList = new ArrayList<>();
|
||||
for (SubscriptionInfoEntity info : mSubInfoEntityList) {
|
||||
subList.add(info);
|
||||
}
|
||||
return subList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_PREFERENCE_SIM;
|
||||
return new ArrayList<>(mSubInfoEntityList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAvailableSubInfoChanged(List<SubscriptionInfoEntity> subInfoEntityList) {
|
||||
mSubInfoEntityList = subInfoEntityList;
|
||||
mPreferenceCategory.setVisible(isAvailable());
|
||||
if (mPreferenceCategory != null) {
|
||||
mPreferenceCategory.setVisible(isAvailable());
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 The Android Open Source 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.android.settings.network;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.widget.PreferenceCategoryController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
|
||||
public class NetworkProviderSimsCategoryController extends PreferenceCategoryController implements
|
||||
LifecycleObserver {
|
||||
private static final String LOG_TAG = "NetworkProviderSimsCategoryController";
|
||||
private static final String KEY_PREFERENCE_CATEGORY_SIM = "provider_model_sim_category";
|
||||
private NetworkProviderSimListController mNetworkProviderSimListController;
|
||||
private PreferenceCategory mPreferenceCategory;
|
||||
|
||||
public NetworkProviderSimsCategoryController(Context context, String key, Lifecycle lifecycle,
|
||||
LifecycleOwner lifecycleOwner) {
|
||||
super(context, key);
|
||||
mNetworkProviderSimListController =
|
||||
new NetworkProviderSimListController(mContext, lifecycle, lifecycleOwner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
if (mNetworkProviderSimListController == null
|
||||
|| !mNetworkProviderSimListController.isAvailable()) {
|
||||
return CONDITIONALLY_UNAVAILABLE;
|
||||
} else {
|
||||
return AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mNetworkProviderSimListController.displayPreference(screen);
|
||||
mPreferenceCategory = screen.findPreference(KEY_PREFERENCE_CATEGORY_SIM);
|
||||
if (mPreferenceCategory == null) {
|
||||
Log.d(LOG_TAG, "displayPreference(), Can not find the category.");
|
||||
return;
|
||||
}
|
||||
mPreferenceCategory.setVisible(isAvailable());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user