Settings: add sim status listener in about phone
Add sim status listener in about phone to dynamiclly update sim status and phone number info when sim card hot-swap. Change-Id: Iee69f34ca85225ea6286f5ba517681b42366a71c CRs-Fixed: 2978481 Signed-off-by: Pranav Vashi <neobuddy89@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.os.Bundle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -61,6 +62,12 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.IntentFilter;
|
||||
|
||||
import com.android.internal.telephony.IccCardConstants;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
|
||||
@SearchIndexable
|
||||
public class MyDeviceInfoFragment extends DashboardFragment
|
||||
implements DeviceNamePreferenceController.DeviceNamePreferenceHost {
|
||||
@@ -69,6 +76,17 @@ public class MyDeviceInfoFragment extends DashboardFragment
|
||||
private static final String KEY_EID_INFO = "eid_info";
|
||||
private static final String KEY_MY_DEVICE_INFO_HEADER = "my_device_info_header";
|
||||
|
||||
private final BroadcastReceiver mSimStateReceiver = new BroadcastReceiver() {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(action)) {
|
||||
String state = intent.getStringExtra(IccCardConstants.INTENT_KEY_ICC_STATE);
|
||||
Log.d(LOG_TAG, "Received ACTION_SIM_STATE_CHANGED: " + state);
|
||||
updatePreferenceStates();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private BuildNumberPreferenceController mBuildNumberPreferenceController;
|
||||
|
||||
@Override
|
||||
@@ -95,6 +113,29 @@ public class MyDeviceInfoFragment extends DashboardFragment
|
||||
initHeader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
context.unregisterReceiver(mSimStateReceiver);
|
||||
} else {
|
||||
Log.i(LOG_TAG, "context already null, not unregistering SimStateReceiver");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
context.registerReceiver(mSimStateReceiver,
|
||||
new IntentFilter(TelephonyIntents.ACTION_SIM_STATE_CHANGED));
|
||||
} else {
|
||||
Log.i(LOG_TAG, "context is null, not registering SimStateReceiver");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLogTag() {
|
||||
return LOG_TAG;
|
||||
|
||||
Reference in New Issue
Block a user