Establish the Activity which hosts Settings panels through the PanelFragment. The Activity's purpose is to validate the intent data coming in, including: - Called with startActivityForResult (so we can log who is calling) - Intent has the proper intent extra to link to a Panel The fragment takes the Panelable data and builds a Settings Panel. Each panel will have: - Title - List of Slices - Link to underlying content The Panelable interface is created to provide all of those datums, and the new FetureProvider provides the Panelables by linking them with keys. The keys will eventually become public APIs with CTS tests.For now, we store them locally. I included an exmaple panel, the InternetConnectivityPanel which currently shows Wifi and Airplane mode. Screenshot: https://screenshot.googleplex.com/c6sv7ZzQ5OJ Bug: 117804089 Test: make -j40 RunSettingsRobotest Test: Manual app Change-Id: I1932f7179cc32088acd6413a736901ddf9651892
149 lines
5.1 KiB
Java
149 lines
5.1 KiB
Java
/*
|
|
* Copyright (C) 2016 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;
|
|
|
|
import static android.provider.SettingsSlicesContract.KEY_AIRPLANE_MODE;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.pm.PackageManager;
|
|
import android.os.SystemProperties;
|
|
import android.text.TextUtils;
|
|
|
|
import androidx.fragment.app.Fragment;
|
|
import androidx.preference.Preference;
|
|
import androidx.preference.PreferenceScreen;
|
|
import androidx.preference.SwitchPreference;
|
|
|
|
import com.android.internal.telephony.TelephonyIntents;
|
|
import com.android.internal.telephony.TelephonyProperties;
|
|
import com.android.settings.AirplaneModeEnabler;
|
|
import com.android.settings.R;
|
|
import com.android.settings.core.TogglePreferenceController;
|
|
import com.android.settings.overlay.FeatureFactory;
|
|
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
|
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
import com.android.settingslib.core.lifecycle.events.OnPause;
|
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
|
|
|
public class AirplaneModePreferenceController extends TogglePreferenceController
|
|
implements LifecycleObserver, OnResume, OnPause,
|
|
AirplaneModeEnabler.OnAirplaneModeChangedListener {
|
|
|
|
public static final int REQUEST_CODE_EXIT_ECM = 1;
|
|
|
|
private static final String EXIT_ECM_RESULT = "exit_ecm_result";
|
|
|
|
private Fragment mFragment;
|
|
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
|
private AirplaneModeEnabler mAirplaneModeEnabler;
|
|
private SwitchPreference mAirplaneModePreference;
|
|
|
|
public AirplaneModePreferenceController(Context context, String key) {
|
|
super(context, key);
|
|
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
|
mAirplaneModeEnabler = new AirplaneModeEnabler(mContext, mMetricsFeatureProvider, this);
|
|
}
|
|
|
|
public void setFragment(Fragment hostFragment) {
|
|
mFragment = hostFragment;
|
|
}
|
|
|
|
@Override
|
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
|
if (KEY_AIRPLANE_MODE.equals(preference.getKey()) && Boolean.parseBoolean(
|
|
SystemProperties.get(TelephonyProperties.PROPERTY_INECM_MODE))) {
|
|
// In ECM mode launch ECM app dialog
|
|
if (mFragment != null) {
|
|
mFragment.startActivityForResult(
|
|
new Intent(TelephonyIntents.ACTION_SHOW_NOTICE_ECM_BLOCK_OTHERS, null),
|
|
REQUEST_CODE_EXIT_ECM);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
@Override
|
|
public void displayPreference(PreferenceScreen screen) {
|
|
super.displayPreference(screen);
|
|
if (isAvailable()) {
|
|
mAirplaneModePreference = (SwitchPreference) screen.findPreference(getPreferenceKey());
|
|
}
|
|
}
|
|
|
|
public static boolean isAvailable(Context context) {
|
|
return context.getResources().getBoolean(R.bool.config_show_toggle_airplane)
|
|
&& !context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK);
|
|
}
|
|
|
|
@Override
|
|
public boolean isSliceable() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
@AvailabilityStatus
|
|
public int getAvailabilityStatus() {
|
|
return isAvailable(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
if (isAvailable()) {
|
|
mAirplaneModeEnabler.resume();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onPause() {
|
|
if (isAvailable()) {
|
|
mAirplaneModeEnabler.pause();
|
|
}
|
|
}
|
|
|
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
if (requestCode == REQUEST_CODE_EXIT_ECM) {
|
|
Boolean isChoiceYes = data.getBooleanExtra(EXIT_ECM_RESULT, false);
|
|
// Set Airplane mode based on the return value and checkbox state
|
|
mAirplaneModeEnabler.setAirplaneModeInECM(isChoiceYes,
|
|
mAirplaneModePreference.isChecked());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean isChecked() {
|
|
return mAirplaneModeEnabler.isAirplaneModeOn();
|
|
}
|
|
|
|
@Override
|
|
public boolean setChecked(boolean isChecked) {
|
|
if (isChecked() == isChecked) {
|
|
return false;
|
|
}
|
|
mAirplaneModeEnabler.setAirplaneMode(isChecked);
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public void onAirplaneModeChanged(boolean isAirplaneModeOn) {
|
|
if (mAirplaneModePreference != null) {
|
|
mAirplaneModePreference.setChecked(isAirplaneModeOn);
|
|
}
|
|
}
|
|
}
|