Clean up lifecycle in MobileNetworkSettings

To avoid double registering, which prevent potential issues and could
improve latency.

Since DashboardFragment already supported register lifecycle
automatically for the controllers bound by XML which implements
androidx.lifecycle.Lifecycle, so doing a cleanup to prevent register
lifecycle event manually (doubling).

Bug: 149338098
Test: temporarily add logging to make sure the lifecycle method is
      called and only called once
Change-Id: I4dbc36414991ef6b599be61aa77ff0dc8c52468c
This commit is contained in:
Chaohui Wang
2022-05-25 12:25:43 +08:00
parent fa878f2f26
commit 866b79c245
17 changed files with 38 additions and 74 deletions

View File

@@ -25,7 +25,6 @@ import android.os.Looper;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.Preference;
@@ -52,10 +51,9 @@ public class DataDuringCallsPreferenceController extends TelephonyTogglePreferen
super(context, preferenceKey);
}
public void init(Lifecycle lifecycle, int subId) {
void init(int subId) {
this.mSubId = subId;
mManager = mContext.getSystemService(TelephonyManager.class).createForSubscriptionId(subId);
lifecycle.addObserver(this);
}
@OnLifecycleEvent(ON_RESUME)