Files
app_Settings/src/com/android/settings/network/telephony/DataServiceSetupPreferenceController.java
Weng Su 7822750c31 Enable Carrier-Config cache for Settings
- Since the "Mobile-Data Details Settings" (NETWORK_OPERATOR_SETTINGS) will query Carrier-Config around 70 times during launching, use the Carrier-Config cache to reduce 69 times to speed up the launching time.

- It takes about 3ms to query a Carrier-Config each time.

- Create a singleton class to share the Carrier-Config for all
sub-settings.

Bug: 204135235
Test: manual test
atest -c ApnPreferenceControllerTest \
         AutoSelectPreferenceControllerTest \
         BackupCallingPreferenceControllerTest \
         CarrierConfigCacheTest \
         CarrierPreferenceControllerTest \
         CarrierSettingsVersionPreferenceControllerTest \
         DataServiceSetupPreferenceControllerTest \
         Enable2gPreferenceControllerTest \
         EnabledNetworkModePreferenceControllerTest \
         Enhanced4gBasePreferenceControllerTest \
         MobileNetworkUtilsTest \
         NetworkProviderBackupCallingGroupTest \
         NrAdvancedCallingPreferenceControllerTest \
         PreferredNetworkModePreferenceControllerTest \
         TelephonyTogglePreferenceControllerTest \
         WifiPickerTrackerHelperTest
make RunSettingsRoboTests \
     ROBOTEST_FILTER=ContactDiscoveryPreferenceControllerTest
make RunSettingsRoboTests \
     ROBOTEST_FILTER=VideoCallingPreferenceControllerTest

Change-Id: I26f9ac115a754910b5d59e820703f1a0e701bb7f
2022-01-14 23:28:50 +08:00

86 lines
3.1 KiB
Java

/*
* Copyright (C) 2018 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.telephony;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import androidx.preference.Preference;
import com.android.settings.network.CarrierConfigCache;
/**
* Preference controller for "Data service setup"
*/
public class DataServiceSetupPreferenceController extends TelephonyBasePreferenceController {
private CarrierConfigCache mCarrierConfigCache;
private TelephonyManager mTelephonyManager;
private String mSetupUrl;
public DataServiceSetupPreferenceController(Context context, String key) {
super(context, key);
mCarrierConfigCache = CarrierConfigCache.getInstance(context);
mTelephonyManager = context.getSystemService(TelephonyManager.class);
mSetupUrl = Settings.Global.getString(mContext.getContentResolver(),
Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
}
@Override
public int getAvailabilityStatus(int subId) {
final PersistableBundle carrierConfig = mCarrierConfigCache.getConfigForSubId(subId);
return subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
&& carrierConfig != null
&& !carrierConfig.getBoolean(
CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)
&& mTelephonyManager.isLteCdmaEvdoGsmWcdmaEnabled() && !TextUtils.isEmpty(mSetupUrl)
? AVAILABLE
: CONDITIONALLY_UNAVAILABLE;
}
public void init(int subId) {
mSubId = subId;
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
.createForSubscriptionId(mSubId);
}
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
if (!TextUtils.isEmpty(mSetupUrl)) {
String imsi = mTelephonyManager.getSubscriberId();
if (imsi == null) {
imsi = "";
}
final String url = TextUtils.expandTemplate(mSetupUrl, imsi).toString();
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
mContext.startActivity(intent);
}
return true;
}
return false;
}
}