blob: d95f3281b5604cb1d574b1ac3fae2aefa7ab51a0 [file] [log] [blame]
package com.android.providers.partnerbookmarks;
import android.content.Context;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
import android.util.Log;
/**
* <pre>
* author : zhangtianwen
* e-mail : tianwen.zhang@t2mobile.com
* time : 2021/07/27
* version: 1.0
* </pre>
*/
public class CarrierBrowserUtils {
private static final String TAG = "CarrierBrowserUtils";
private static final String CARRIER_CONFIG_KEY_HOME_PAGE = "home_page";
private static final String CARRIER_CONFIG_KEY_BOOKMARKS = "bookmarks";
private static final String CARRIER_CONFIG_KEY_BOOKMARKS_FOLDER = "bookmarks_folder_name";
public static CharSequence getCarrierHomePage(Context context) {
return getCarrierHomePage(context, getCarrierConfig(context));
}
public static CharSequence[] getCarrierBookMark(Context context) {
return getCarrierBookMark(context, getCarrierConfig(context));
}
public static CharSequence getCarrierBookMarksFolderName(Context context) {
return getCarrierBookMarkFolderName(context, getCarrierConfig(context));
}
private static CharSequence getCarrierHomePage(Context context, Bundle bundle) {
if (bundle != null) {
String homePage = bundle.getString(CARRIER_CONFIG_KEY_HOME_PAGE);
Log.d(TAG, "carrier config home page " + homePage);
if (!TextUtils.isEmpty(homePage)) {
return homePage;
}
}
return context.getResources().getText(R.string.home_page);
}
private static CharSequence[] getCarrierBookMark(Context context, Bundle bundle) {
if (bundle != null) {
String[] bookmarks = bundle.getStringArray(CARRIER_CONFIG_KEY_BOOKMARKS);
if (bookmarks != null && bookmarks.length > 0) {
for (String bookmark : bookmarks) {
Log.d(TAG, "carrier config bookmark " + bookmark);
}
return bookmarks;
}
}
return context.getResources().getTextArray(R.array.bookmarks);
}
private static CharSequence getCarrierBookMarkFolderName(Context context, Bundle bundle) {
if (bundle != null) {
String bookmarks_folder_name = bundle.getString(CARRIER_CONFIG_KEY_BOOKMARKS_FOLDER);
Log.d(TAG, "carrier config folder name " + bookmarks_folder_name);
if (!TextUtils.isEmpty(bookmarks_folder_name)) {
return bookmarks_folder_name;
}
}
return context.getResources().getText(R.string.bookmarks_folder_name);
}
private static Bundle getCarrierConfig(Context context) {
Bundle bundle = new Bundle();
try {
CarrierConfigManager carrierConfigManager = (CarrierConfigManager) context.getSystemService(Context.CARRIER_CONFIG_SERVICE);
PersistableBundle config = carrierConfigManager.getConfigLocked();
bundle.putAll(config);
} catch (Exception e) {
Log.d(TAG, "getCustomerCarrierConfig error = " + e.getMessage());
}
return bundle;
}
}