Implement off state for SIM details page

When a subscription is disabled, we need to hide most things on the
details page. The UX mocks called for leaving in a few things such as
the data usage header and some carrier information, but in tests I've
done it looks like the telephony APIs don't have any of that available
when the subscription is disabled. So for now the only thing left on the
page in the disabled case is the on/off toggle at the very top.

Fixes: 129665956
Test: make RunSettingsRoboTests
Change-Id: I98f4590fca38d03b1e5ff2cf0d2b4876d2adf936
This commit is contained in:
Antony Sargent
2019-04-24 10:44:37 -07:00
parent 172d03c758
commit 74d8d9c31f
4 changed files with 357 additions and 156 deletions

View File

@@ -0,0 +1,91 @@
/*
* Copyright (C) 2019 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 static androidx.lifecycle.Lifecycle.Event.ON_PAUSE;
import static androidx.lifecycle.Lifecycle.Event.ON_RESUME;
import android.content.Context;
import android.telephony.SubscriptionManager;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.network.SubscriptionsChangeListener;
public class DisabledSubscriptionController extends BasePreferenceController implements
SubscriptionsChangeListener.SubscriptionsChangeListenerClient, LifecycleObserver {
private PreferenceCategory mCategory;
private int mSubId;
private SubscriptionsChangeListener mChangeListener;
private SubscriptionManager mSubscriptionManager;
public DisabledSubscriptionController(Context context, String preferenceKey) {
super(context, preferenceKey);
mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
mSubscriptionManager = mContext.getSystemService(SubscriptionManager.class);
mChangeListener = new SubscriptionsChangeListener(context, this);
}
public void init(Lifecycle lifecycle, int subId) {
lifecycle.addObserver(this);
mSubId = subId;
}
@OnLifecycleEvent(ON_RESUME)
public void onResume() {
mChangeListener.start();
update();
}
@OnLifecycleEvent(ON_PAUSE)
public void onPause() {
mChangeListener.stop();
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mCategory = screen.findPreference(getPreferenceKey());
update();
}
private void update() {
if (mCategory == null || mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
return;
}
mCategory.setVisible(mSubscriptionManager.isSubscriptionEnabled(mSubId));
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public void onAirplaneModeChanged(boolean airplaneModeEnabled) {
}
@Override
public void onSubscriptionsChanged() {
update();
}
}