Merge "Fix CarrierSettings preference"

This commit is contained in:
Pengquan Meng
2018-11-21 19:38:43 +00:00
committed by Android (Google) Code Review
2 changed files with 88 additions and 1 deletions

View File

@@ -17,6 +17,10 @@
package com.android.settings.network.telephony;
import android.content.Context;
import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.SubscriptionManager;
@@ -62,10 +66,31 @@ public class CarrierPreferenceController extends BasePreferenceController {
@Override
public boolean handlePreferenceTreeClick(Preference preference) {
if (getPreferenceKey().equals(preference.getKey())) {
//TODO(b/117651939): start carrier settings activity
final Intent carrierSettingsIntent = getCarrierSettingsActivityIntent(mSubId);
if (carrierSettingsIntent != null) {
mContext.startActivity(carrierSettingsIntent);
}
return true;
}
return false;
}
private Intent getCarrierSettingsActivityIntent(int subId) {
final PersistableBundle config = mCarrierConfigManager.getConfigForSubId(subId);
final ComponentName cn = ComponentName.unflattenFromString(
config == null ? "" : config.getString(
CarrierConfigManager.KEY_CARRIER_SETTINGS_ACTIVITY_COMPONENT_NAME_STRING,
"" /* default value */));
if (cn == null) return null;
final Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setComponent(cn);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PackageManager pm = mContext.getPackageManager();
final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0 /* flags */);
return resolveInfo != null ? intent : null;
}
}