Move conditional stuff from dashboard/ to homepage package.
dashboard package is not a real place for homepage stuff. Putting Conditionals here makes it easier to refactor it for new homepage in the future Bug: 110405144 Bug: 112485407 Test: robotests Change-Id: If433aeac8766124f0f4f6e5786b93ac1372bb745
This commit is contained in:
@@ -40,9 +40,9 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.R.id;
|
||||
import com.android.settings.dashboard.DashboardData.ConditionHeaderData;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionAdapter;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
|
||||
import com.android.settings.homepage.conditional.Condition;
|
||||
import com.android.settings.homepage.conditional.ConditionAdapter;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
@@ -24,7 +24,7 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.DiffUtil;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.homepage.conditional.Condition;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
|
@@ -36,12 +36,12 @@ import com.android.settings.R;
|
||||
import com.android.settings.core.InstrumentedFragment;
|
||||
import com.android.settings.core.SettingsBaseActivity;
|
||||
import com.android.settings.core.SettingsBaseActivity.CategoryListener;
|
||||
import com.android.settings.dashboard.conditional.Condition;
|
||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||
import com.android.settings.dashboard.conditional.ConditionManager.ConditionListener;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.homepage.conditional.Condition;
|
||||
import com.android.settings.homepage.conditional.ConditionManager;
|
||||
import com.android.settings.homepage.conditional.ConditionManager.ConditionListener;
|
||||
import com.android.settings.homepage.conditional.FocusRecyclerView;
|
||||
import com.android.settings.homepage.conditional.FocusRecyclerView.FocusListener;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ActionBarShadowController;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
public abstract class AbnormalRingerConditionBase extends Condition {
|
||||
|
||||
private final IntentFilter mFilter;
|
||||
|
||||
protected final AudioManager mAudioManager;
|
||||
|
||||
private final RingerModeChangeReceiver mReceiver;
|
||||
|
||||
AbnormalRingerConditionBase(ConditionManager manager) {
|
||||
super(manager);
|
||||
mAudioManager =
|
||||
(AudioManager) mManager.getContext().getSystemService(Context.AUDIO_SERVICE);
|
||||
mReceiver = new RingerModeChangeReceiver(this);
|
||||
|
||||
mFilter = new IntentFilter(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
manager.getContext().registerReceiver(mReceiver, mFilter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {
|
||||
mManager.getContext().getText(R.string.condition_device_muted_action_turn_on_sound)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(
|
||||
new Intent(Settings.ACTION_SOUND_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
mAudioManager.setRingerModeInternal(AudioManager.RINGER_MODE_NORMAL);
|
||||
mAudioManager.setStreamVolume(AudioManager.STREAM_RING, 1, 0 /* flags */);
|
||||
refreshState();
|
||||
}
|
||||
|
||||
static class RingerModeChangeReceiver extends BroadcastReceiver {
|
||||
|
||||
private final AbnormalRingerConditionBase mCondition;
|
||||
|
||||
public RingerModeChangeReceiver(AbnormalRingerConditionBase condition) {
|
||||
mCondition = condition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mCondition.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
|
||||
public class AirplaneModeCondition extends Condition {
|
||||
public static String TAG = "APM_Condition";
|
||||
|
||||
private final Receiver mReceiver;
|
||||
|
||||
private static final IntentFilter AIRPLANE_MODE_FILTER =
|
||||
new IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
|
||||
|
||||
public AirplaneModeCondition(ConditionManager conditionManager) {
|
||||
super(conditionManager);
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
Log.d(TAG, "APM condition refreshed");
|
||||
setActive(WirelessUtils.isAirplaneModeOn(mManager.getContext()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BroadcastReceiver getReceiver() {
|
||||
return mReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntentFilter getIntentFilter() {
|
||||
return AIRPLANE_MODE_FILTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_airplane);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setActive(boolean active) {
|
||||
super.setActive(active);
|
||||
Log.d(TAG, "setActive was called with " + active);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_airplane_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_airplane_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(
|
||||
new Intent(Settings.ACTION_WIRELESS_SETTINGS)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
ConnectivityManager.from(mManager.getContext()).setAirplaneMode(false);
|
||||
setActive(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_AIRPLANE_MODE;
|
||||
}
|
||||
|
||||
public static class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (Intent.ACTION_AIRPLANE_MODE_CHANGED.equals(intent.getAction())) {
|
||||
ConditionManager.get(context).getCondition(AirplaneModeCondition.class)
|
||||
.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.NetworkPolicyManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
public class BackgroundDataCondition extends Condition {
|
||||
|
||||
public BackgroundDataCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
setActive(NetworkPolicyManager.from(mManager.getContext()).getRestrictBackground());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_data_saver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_bg_data_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_bg_data_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(new Intent(mManager.getContext(),
|
||||
Settings.DataUsageSummaryActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_BACKGROUND_DATA;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
NetworkPolicyManager.from(mManager.getContext()).setRestrictBackground(false);
|
||||
setActive(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,113 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.PowerManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.fuelgauge.BatterySaverReceiver;
|
||||
import com.android.settings.fuelgauge.batterysaver.BatterySaverSettings;
|
||||
import com.android.settingslib.fuelgauge.BatterySaverUtils;
|
||||
|
||||
public class BatterySaverCondition extends Condition implements
|
||||
BatterySaverReceiver.BatterySaverListener {
|
||||
|
||||
private final BatterySaverReceiver mReceiver;
|
||||
|
||||
public BatterySaverCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
|
||||
mReceiver = new BatterySaverReceiver(manager.getContext());
|
||||
mReceiver.setBatterySaverListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
PowerManager powerManager = mManager.getContext().getSystemService(PowerManager.class);
|
||||
setActive(powerManager.isPowerSaveMode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_battery_saver_accent_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_battery_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_battery_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[]{mManager.getContext().getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
new SubSettingLauncher(mManager.getContext())
|
||||
.setDestination(BatterySaverSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.battery_saver)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
BatterySaverUtils.setPowerSaveMode(mManager.getContext(), false,
|
||||
/*needFirstTimeWarning*/ false);
|
||||
refreshState();
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_BATTERY_SAVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
mReceiver.setListening(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
mReceiver.setListening(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPowerSaveModeChanged() {
|
||||
ConditionManager.get(mManager.getContext()).getCondition(BatterySaverCondition.class)
|
||||
.refreshState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatteryChanged(boolean pluggedIn) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
public class CellularDataCondition extends Condition {
|
||||
|
||||
private final Receiver mReceiver;
|
||||
|
||||
private static final IntentFilter DATA_CONNECTION_FILTER =
|
||||
new IntentFilter(TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED);
|
||||
|
||||
public CellularDataCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
ConnectivityManager connectivity = mManager.getContext().getSystemService(
|
||||
ConnectivityManager.class);
|
||||
TelephonyManager telephony = mManager.getContext().getSystemService(TelephonyManager.class);
|
||||
if (!connectivity.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)
|
||||
|| telephony.getSimState() != TelephonyManager.SIM_STATE_READY) {
|
||||
setActive(false);
|
||||
return;
|
||||
}
|
||||
setActive(!telephony.isDataEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BroadcastReceiver getReceiver() {
|
||||
return mReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntentFilter getIntentFilter() {
|
||||
return DATA_CONNECTION_FILTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_cellular_off);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_cellular_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_cellular_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_on) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(new Intent(mManager.getContext(),
|
||||
Settings.DataUsageSummaryActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
TelephonyManager telephony = mManager.getContext().getSystemService(
|
||||
TelephonyManager.class);
|
||||
telephony.setDataEnabled(true);
|
||||
setActive(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_CELLULAR_DATA;
|
||||
}
|
||||
|
||||
public static class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (TelephonyIntents.ACTION_ANY_DATA_CONNECTION_STATE_CHANGED.equals(
|
||||
intent.getAction())) {
|
||||
CellularDataCondition condition = ConditionManager.get(context).getCondition(
|
||||
CellularDataCondition.class);
|
||||
if (condition != null) {
|
||||
condition.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
public abstract class Condition {
|
||||
|
||||
private static final String KEY_SILENCE = "silence";
|
||||
private static final String KEY_ACTIVE = "active";
|
||||
private static final String KEY_LAST_STATE = "last_state";
|
||||
|
||||
protected final ConditionManager mManager;
|
||||
protected final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
protected boolean mReceiverRegistered;
|
||||
|
||||
private boolean mIsSilenced;
|
||||
private boolean mIsActive;
|
||||
private long mLastStateChange;
|
||||
|
||||
// All conditions must live in this package.
|
||||
Condition(ConditionManager manager) {
|
||||
this(manager, FeatureFactory.getFactory(manager.getContext()).getMetricsFeatureProvider());
|
||||
}
|
||||
|
||||
Condition(ConditionManager manager, MetricsFeatureProvider metricsFeatureProvider) {
|
||||
mManager = manager;
|
||||
mMetricsFeatureProvider = metricsFeatureProvider;
|
||||
}
|
||||
|
||||
void restoreState(PersistableBundle bundle) {
|
||||
mIsSilenced = bundle.getBoolean(KEY_SILENCE);
|
||||
mIsActive = bundle.getBoolean(KEY_ACTIVE);
|
||||
mLastStateChange = bundle.getLong(KEY_LAST_STATE);
|
||||
}
|
||||
|
||||
boolean saveState(PersistableBundle bundle) {
|
||||
if (mIsSilenced) {
|
||||
bundle.putBoolean(KEY_SILENCE, mIsSilenced);
|
||||
}
|
||||
if (mIsActive) {
|
||||
bundle.putBoolean(KEY_ACTIVE, mIsActive);
|
||||
bundle.putLong(KEY_LAST_STATE, mLastStateChange);
|
||||
}
|
||||
return mIsSilenced || mIsActive;
|
||||
}
|
||||
|
||||
protected void notifyChanged() {
|
||||
mManager.notifyChanged(this);
|
||||
}
|
||||
|
||||
public boolean isSilenced() {
|
||||
return mIsSilenced;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return mIsActive;
|
||||
}
|
||||
|
||||
protected void setActive(boolean active) {
|
||||
if (mIsActive == active) {
|
||||
return;
|
||||
}
|
||||
mIsActive = active;
|
||||
mLastStateChange = System.currentTimeMillis();
|
||||
if (mIsSilenced && !active) {
|
||||
mIsSilenced = false;
|
||||
onSilenceChanged(mIsSilenced);
|
||||
}
|
||||
notifyChanged();
|
||||
}
|
||||
|
||||
public void silence() {
|
||||
if (!mIsSilenced) {
|
||||
mIsSilenced = true;
|
||||
Context context = mManager.getContext();
|
||||
mMetricsFeatureProvider.action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_DISMISS,
|
||||
getMetricsConstant());
|
||||
onSilenceChanged(mIsSilenced);
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void onSilenceChanged(boolean silenced) {
|
||||
final BroadcastReceiver receiver = getReceiver();
|
||||
if (receiver == null) {
|
||||
return;
|
||||
}
|
||||
if (silenced) {
|
||||
if (!mReceiverRegistered) {
|
||||
mManager.getContext().registerReceiver(receiver, getIntentFilter());
|
||||
mReceiverRegistered = true;
|
||||
}
|
||||
} else {
|
||||
if (mReceiverRegistered) {
|
||||
mManager.getContext().unregisterReceiver(receiver);
|
||||
mReceiverRegistered = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected BroadcastReceiver getReceiver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected IntentFilter getIntentFilter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean shouldShow() {
|
||||
return isActive() && !isSilenced();
|
||||
}
|
||||
|
||||
long getLastChange() {
|
||||
return mLastStateChange;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
}
|
||||
|
||||
// State.
|
||||
public abstract void refreshState();
|
||||
|
||||
public abstract int getMetricsConstant();
|
||||
|
||||
// UI.
|
||||
public abstract Drawable getIcon();
|
||||
public abstract CharSequence getTitle();
|
||||
public abstract CharSequence getSummary();
|
||||
public abstract CharSequence[] getActions();
|
||||
|
||||
public abstract void onPrimaryClick();
|
||||
public abstract void onActionClick(int index);
|
||||
}
|
@@ -1,187 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.dashboard.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardAdapter.DashboardItemHolder;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.WirelessUtils;
|
||||
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
public class ConditionAdapter extends RecyclerView.Adapter<DashboardItemHolder> {
|
||||
public static final String TAG = "ConditionAdapter";
|
||||
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private List<Condition> mConditions;
|
||||
private boolean mExpanded;
|
||||
|
||||
private View.OnClickListener mConditionClickListener = new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//TODO: get rid of setTag/getTag
|
||||
Condition condition = (Condition) v.getTag();
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_SETTINGS_CONDITION_CLICK,
|
||||
condition.getMetricsConstant());
|
||||
condition.onPrimaryClick();
|
||||
}
|
||||
};
|
||||
|
||||
@VisibleForTesting
|
||||
ItemTouchHelper.SimpleCallback mSwipeCallback = new ItemTouchHelper.SimpleCallback(0,
|
||||
ItemTouchHelper.START | ItemTouchHelper.END) {
|
||||
@Override
|
||||
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder,
|
||||
RecyclerView.ViewHolder target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||
return viewHolder.getItemViewType() == R.layout.condition_tile
|
||||
? super.getSwipeDirs(recyclerView, viewHolder) : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
Object item = getItem(viewHolder.getItemId());
|
||||
// item can become null when running monkey
|
||||
if (item != null) {
|
||||
((Condition) item).silence();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public ConditionAdapter(Context context, List<Condition> conditions, boolean expanded) {
|
||||
mContext = context;
|
||||
mConditions = conditions;
|
||||
mExpanded = expanded;
|
||||
mMetricsFeatureProvider = FeatureFactory.getFactory(context).getMetricsFeatureProvider();
|
||||
|
||||
setHasStableIds(true);
|
||||
}
|
||||
|
||||
public Object getItem(long itemId) {
|
||||
for (Condition condition : mConditions) {
|
||||
if (Objects.hash(condition.getTitle()) == itemId) {
|
||||
return condition;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DashboardItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
return new DashboardItemHolder(LayoutInflater.from(parent.getContext()).inflate(
|
||||
viewType, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
bindViews(mConditions.get(position), holder,
|
||||
position == mConditions.size() - 1, mConditionClickListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return Objects.hash(mConditions.get(position).getTitle());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return R.layout.condition_tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
if (mExpanded) {
|
||||
return mConditions.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void addDismissHandling(final RecyclerView recyclerView) {
|
||||
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mSwipeCallback);
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView);
|
||||
}
|
||||
|
||||
private void bindViews(final Condition condition,
|
||||
DashboardItemHolder view, boolean isLastItem,
|
||||
View.OnClickListener onClickListener) {
|
||||
if (condition instanceof AirplaneModeCondition) {
|
||||
Log.d(TAG, "Airplane mode condition has been bound with "
|
||||
+ "isActive=" + condition.isActive() + ". Airplane mode is currently " +
|
||||
WirelessUtils.isAirplaneModeOn(condition.mManager.getContext()));
|
||||
}
|
||||
View card = view.itemView.findViewById(R.id.content);
|
||||
card.setTag(condition);
|
||||
card.setOnClickListener(onClickListener);
|
||||
view.icon.setImageDrawable(condition.getIcon());
|
||||
view.title.setText(condition.getTitle());
|
||||
|
||||
CharSequence[] actions = condition.getActions();
|
||||
final boolean hasButtons = actions.length > 0;
|
||||
setViewVisibility(view.itemView, R.id.buttonBar, hasButtons);
|
||||
|
||||
view.summary.setText(condition.getSummary());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Button button = (Button) view.itemView.findViewById(i == 0
|
||||
? R.id.first_action : R.id.second_action);
|
||||
if (actions.length > i) {
|
||||
button.setVisibility(View.VISIBLE);
|
||||
button.setText(actions[i]);
|
||||
final int index = i;
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Context context = v.getContext();
|
||||
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
|
||||
.action(context, MetricsEvent.ACTION_SETTINGS_CONDITION_BUTTON,
|
||||
condition.getMetricsConstant());
|
||||
condition.onActionClick(index);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
button.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
setViewVisibility(view.itemView, R.id.divider, !isLastItem);
|
||||
}
|
||||
|
||||
private void setViewVisibility(View containerView, int viewId, boolean visible) {
|
||||
View view = containerView.findViewById(viewId);
|
||||
if (view != null) {
|
||||
view.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,306 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.PersistableBundle;
|
||||
import android.util.Log;
|
||||
import android.util.Xml;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
public class ConditionManager implements LifecycleObserver, OnResume, OnPause {
|
||||
|
||||
private static final String TAG = "ConditionManager";
|
||||
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private static final String PKG = "com.android.settings.dashboard.conditional.";
|
||||
|
||||
private static final String FILE_NAME = "condition_state.xml";
|
||||
private static final String TAG_CONDITIONS = "cs";
|
||||
private static final String TAG_CONDITION = "c";
|
||||
private static final String ATTR_CLASS = "cls";
|
||||
|
||||
private static ConditionManager sInstance;
|
||||
|
||||
private final Context mContext;
|
||||
private final ArrayList<Condition> mConditions;
|
||||
private File mXmlFile;
|
||||
|
||||
private final ArrayList<ConditionListener> mListeners = new ArrayList<>();
|
||||
|
||||
private ConditionManager(Context context, boolean loadConditionsNow) {
|
||||
mContext = context;
|
||||
mConditions = new ArrayList<>();
|
||||
if (loadConditionsNow) {
|
||||
Log.d(TAG, "conditions loading synchronously");
|
||||
ConditionLoader loader = new ConditionLoader();
|
||||
loader.onPostExecute(loader.doInBackground());
|
||||
} else {
|
||||
Log.d(TAG, "conditions loading asychronously");
|
||||
new ConditionLoader().execute();
|
||||
}
|
||||
}
|
||||
|
||||
public void refreshAll() {
|
||||
final int N = mConditions.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
mConditions.get(i).refreshState();
|
||||
}
|
||||
}
|
||||
|
||||
private void readFromXml(File xmlFile, ArrayList<Condition> conditions) {
|
||||
if (DEBUG) Log.d(TAG, "Reading from " + xmlFile.toString());
|
||||
try {
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
FileReader in = new FileReader(xmlFile);
|
||||
parser.setInput(in);
|
||||
int state = parser.getEventType();
|
||||
|
||||
while (state != XmlPullParser.END_DOCUMENT) {
|
||||
if (TAG_CONDITION.equals(parser.getName())) {
|
||||
int depth = parser.getDepth();
|
||||
String clz = parser.getAttributeValue("", ATTR_CLASS);
|
||||
if (!clz.startsWith(PKG)) {
|
||||
clz = PKG + clz;
|
||||
}
|
||||
Condition condition = createCondition(Class.forName(clz));
|
||||
PersistableBundle bundle = PersistableBundle.restoreFromXml(parser);
|
||||
if (DEBUG) Log.d(TAG, "Reading " + clz + " -- " + bundle);
|
||||
if (condition != null) {
|
||||
condition.restoreState(bundle);
|
||||
conditions.add(condition);
|
||||
} else {
|
||||
Log.e(TAG, "failed to add condition: " + clz);
|
||||
}
|
||||
while (parser.getDepth() > depth) {
|
||||
parser.next();
|
||||
}
|
||||
}
|
||||
state = parser.next();
|
||||
}
|
||||
in.close();
|
||||
} catch (XmlPullParserException | IOException | ClassNotFoundException e) {
|
||||
Log.w(TAG, "Problem reading " + FILE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void saveToXml() {
|
||||
if (DEBUG) Log.d(TAG, "Writing to " + mXmlFile.toString());
|
||||
try {
|
||||
XmlSerializer serializer = Xml.newSerializer();
|
||||
FileWriter writer = new FileWriter(mXmlFile);
|
||||
serializer.setOutput(writer);
|
||||
|
||||
serializer.startDocument("UTF-8", true);
|
||||
serializer.startTag("", TAG_CONDITIONS);
|
||||
|
||||
final int N = mConditions.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
PersistableBundle bundle = new PersistableBundle();
|
||||
if (mConditions.get(i).saveState(bundle)) {
|
||||
serializer.startTag("", TAG_CONDITION);
|
||||
final String clz = mConditions.get(i).getClass().getSimpleName();
|
||||
serializer.attribute("", ATTR_CLASS, clz);
|
||||
bundle.saveToXml(serializer);
|
||||
serializer.endTag("", TAG_CONDITION);
|
||||
}
|
||||
}
|
||||
|
||||
serializer.endTag("", TAG_CONDITIONS);
|
||||
serializer.flush();
|
||||
writer.close();
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
Log.w(TAG, "Problem writing " + FILE_NAME, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMissingConditions(ArrayList<Condition> conditions) {
|
||||
addIfMissing(AirplaneModeCondition.class, conditions);
|
||||
addIfMissing(HotspotCondition.class, conditions);
|
||||
addIfMissing(DndCondition.class, conditions);
|
||||
addIfMissing(BatterySaverCondition.class, conditions);
|
||||
addIfMissing(CellularDataCondition.class, conditions);
|
||||
addIfMissing(BackgroundDataCondition.class, conditions);
|
||||
addIfMissing(WorkModeCondition.class, conditions);
|
||||
addIfMissing(NightDisplayCondition.class, conditions);
|
||||
addIfMissing(RingerMutedCondition.class, conditions);
|
||||
addIfMissing(RingerVibrateCondition.class, conditions);
|
||||
Collections.sort(conditions, CONDITION_COMPARATOR);
|
||||
}
|
||||
|
||||
private void addIfMissing(Class<? extends Condition> clz, ArrayList<Condition> conditions) {
|
||||
if (getCondition(clz, conditions) == null) {
|
||||
if (DEBUG) Log.d(TAG, "Adding missing " + clz.getName());
|
||||
Condition condition = createCondition(clz);
|
||||
if (condition != null) {
|
||||
conditions.add(condition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Condition createCondition(Class<?> clz) {
|
||||
if (AirplaneModeCondition.class == clz) {
|
||||
return new AirplaneModeCondition(this);
|
||||
} else if (HotspotCondition.class == clz) {
|
||||
return new HotspotCondition(this);
|
||||
} else if (DndCondition.class == clz) {
|
||||
return new DndCondition(this);
|
||||
} else if (BatterySaverCondition.class == clz) {
|
||||
return new BatterySaverCondition(this);
|
||||
} else if (CellularDataCondition.class == clz) {
|
||||
return new CellularDataCondition(this);
|
||||
} else if (BackgroundDataCondition.class == clz) {
|
||||
return new BackgroundDataCondition(this);
|
||||
} else if (WorkModeCondition.class == clz) {
|
||||
return new WorkModeCondition(this);
|
||||
} else if (NightDisplayCondition.class == clz) {
|
||||
return new NightDisplayCondition(this);
|
||||
} else if (RingerMutedCondition.class == clz) {
|
||||
return new RingerMutedCondition(this);
|
||||
} else if (RingerVibrateCondition.class == clz) {
|
||||
return new RingerVibrateCondition(this);
|
||||
}
|
||||
Log.e(TAG, "unknown condition class: " + clz.getSimpleName());
|
||||
return null;
|
||||
}
|
||||
|
||||
Context getContext() {
|
||||
return mContext;
|
||||
}
|
||||
|
||||
public <T extends Condition> T getCondition(Class<T> clz) {
|
||||
return getCondition(clz, mConditions);
|
||||
}
|
||||
|
||||
private <T extends Condition> T getCondition(Class<T> clz, List<Condition> conditions) {
|
||||
final int N = conditions.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (clz.equals(conditions.get(i).getClass())) {
|
||||
return (T) conditions.get(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Condition> getConditions() {
|
||||
return mConditions;
|
||||
}
|
||||
|
||||
public List<Condition> getVisibleConditions() {
|
||||
List<Condition> conditions = new ArrayList<>();
|
||||
final int N = mConditions.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (mConditions.get(i).shouldShow()) {
|
||||
conditions.add(mConditions.get(i));
|
||||
}
|
||||
}
|
||||
return conditions;
|
||||
}
|
||||
|
||||
public void notifyChanged(Condition condition) {
|
||||
saveToXml();
|
||||
Collections.sort(mConditions, CONDITION_COMPARATOR);
|
||||
final int N = mListeners.size();
|
||||
for (int i = 0; i < N; i++) {
|
||||
mListeners.get(i).onConditionsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(ConditionListener listener) {
|
||||
mListeners.add(listener);
|
||||
listener.onConditionsChanged();
|
||||
}
|
||||
|
||||
public void remListener(ConditionListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
for (int i = 0, size = mConditions.size(); i < size; i++) {
|
||||
mConditions.get(i).onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
for (int i = 0, size = mConditions.size(); i < size; i++) {
|
||||
mConditions.get(i).onPause();
|
||||
}
|
||||
}
|
||||
|
||||
private class ConditionLoader extends AsyncTask<Void, Void, ArrayList<Condition>> {
|
||||
@Override
|
||||
protected ArrayList<Condition> doInBackground(Void... params) {
|
||||
Log.d(TAG, "loading conditions from xml");
|
||||
ArrayList<Condition> conditions = new ArrayList<>();
|
||||
mXmlFile = new File(mContext.getFilesDir(), FILE_NAME);
|
||||
if (mXmlFile.exists()) {
|
||||
readFromXml(mXmlFile, conditions);
|
||||
}
|
||||
addMissingConditions(conditions);
|
||||
return conditions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<Condition> conditions) {
|
||||
Log.d(TAG, "conditions loaded from xml, refreshing conditions");
|
||||
mConditions.clear();
|
||||
mConditions.addAll(conditions);
|
||||
refreshAll();
|
||||
}
|
||||
}
|
||||
|
||||
public static ConditionManager get(Context context) {
|
||||
return get(context, true);
|
||||
}
|
||||
|
||||
public static ConditionManager get(Context context, boolean loadConditionsNow) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ConditionManager(context.getApplicationContext(), loadConditionsNow);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public interface ConditionListener {
|
||||
void onConditionsChanged();
|
||||
}
|
||||
|
||||
private static final Comparator<Condition> CONDITION_COMPARATOR = new Comparator<Condition>() {
|
||||
@Override
|
||||
public int compare(Condition lhs, Condition rhs) {
|
||||
return Long.compare(lhs.getLastChange(), rhs.getLastChange());
|
||||
}
|
||||
};
|
||||
}
|
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.provider.Settings.Global;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.notification.ZenModeSettings;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
public class DndCondition extends Condition {
|
||||
|
||||
private static final String TAG = "DndCondition";
|
||||
private static final String KEY_STATE = "state";
|
||||
|
||||
private boolean mRegistered;
|
||||
|
||||
@VisibleForTesting
|
||||
static final IntentFilter DND_FILTER =
|
||||
new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL);
|
||||
@VisibleForTesting
|
||||
protected ZenModeConfig mConfig;
|
||||
|
||||
private int mZen;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
public DndCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mReceiver = new Receiver();
|
||||
mManager.getContext().registerReceiver(mReceiver, DND_FILTER);
|
||||
mRegistered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
NotificationManager notificationManager =
|
||||
mManager.getContext().getSystemService(NotificationManager.class);
|
||||
mZen = notificationManager.getZenMode();
|
||||
boolean zenModeEnabled = mZen != Settings.Global.ZEN_MODE_OFF;
|
||||
if (zenModeEnabled) {
|
||||
mConfig = notificationManager.getZenModeConfig();
|
||||
} else {
|
||||
mConfig = null;
|
||||
}
|
||||
setActive(zenModeEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean saveState(PersistableBundle bundle) {
|
||||
bundle.putInt(KEY_STATE, mZen);
|
||||
return super.saveState(bundle);
|
||||
}
|
||||
|
||||
@Override
|
||||
void restoreState(PersistableBundle bundle) {
|
||||
super.restoreState(bundle);
|
||||
mZen = bundle.getInt(KEY_STATE, Global.ZEN_MODE_OFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_do_not_disturb_on_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_zen_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return ZenModeConfig.getDescription(mManager.getContext(), mZen != Global.ZEN_MODE_OFF,
|
||||
mConfig, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] { mManager.getContext().getString(R.string.condition_turn_off) };
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
new SubSettingLauncher(mManager.getContext())
|
||||
.setDestination(ZenModeSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.zen_mode_settings_title)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
NotificationManager notificationManager = mManager.getContext().getSystemService(
|
||||
NotificationManager.class);
|
||||
notificationManager.setZenMode(Settings.Global.ZEN_MODE_OFF, null, TAG);
|
||||
setActive(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_DND;
|
||||
}
|
||||
|
||||
public static class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED_INTERNAL
|
||||
.equals(intent.getAction())) {
|
||||
final Condition condition =
|
||||
ConditionManager.get(context).getCondition(DndCondition.class);
|
||||
if (condition != null) {
|
||||
condition.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
if (!mRegistered) {
|
||||
mManager.getContext().registerReceiver(mReceiver, DND_FILTER);
|
||||
mRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (mRegistered) {
|
||||
mManager.getContext().unregisterReceiver(mReceiver);
|
||||
mRegistered = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* Copyright 2015, 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.dashboard.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Version of RecyclerView that can have listeners for onWindowFocusChanged.
|
||||
*/
|
||||
public class FocusRecyclerView extends RecyclerView {
|
||||
|
||||
private FocusListener mListener;
|
||||
|
||||
public FocusRecyclerView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasWindowFocus) {
|
||||
super.onWindowFocusChanged(hasWindowFocus);
|
||||
if (mListener != null) {
|
||||
mListener.onWindowFocusChanged(hasWindowFocus);
|
||||
}
|
||||
}
|
||||
|
||||
public void setListener(FocusListener listener) {
|
||||
mListener = listener;
|
||||
}
|
||||
|
||||
public interface FocusListener {
|
||||
void onWindowFocusChanged(boolean hasWindowFocus);
|
||||
}
|
||||
}
|
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2015 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.dashboard.conditional;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.wifi.WifiConfiguration;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TetherSettings;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settingslib.RestrictedLockUtils;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
public class HotspotCondition extends Condition {
|
||||
|
||||
private final WifiManager mWifiManager;
|
||||
private final Receiver mReceiver;
|
||||
|
||||
private static final IntentFilter WIFI_AP_STATE_FILTER =
|
||||
new IntentFilter(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
|
||||
|
||||
public HotspotCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mWifiManager = mManager.getContext().getSystemService(WifiManager.class);
|
||||
mReceiver = new Receiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
boolean wifiTetherEnabled = mWifiManager.isWifiApEnabled();
|
||||
setActive(wifiTetherEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected BroadcastReceiver getReceiver() {
|
||||
return mReceiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IntentFilter getIntentFilter() {
|
||||
return WIFI_AP_STATE_FILTER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_hotspot);
|
||||
}
|
||||
|
||||
private String getSsid() {
|
||||
WifiConfiguration wifiConfig = mWifiManager.getWifiApConfiguration();
|
||||
if (wifiConfig == null) {
|
||||
return mManager.getContext().getString(
|
||||
com.android.internal.R.string.wifi_tether_configure_ssid_default);
|
||||
} else {
|
||||
return wifiConfig.SSID;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_hotspot_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_hotspot_summary, getSsid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
final Context context = mManager.getContext();
|
||||
if (RestrictedLockUtils.hasBaseUserRestriction(context,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId())) {
|
||||
return new CharSequence[0];
|
||||
}
|
||||
return new CharSequence[] {context.getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
new SubSettingLauncher(mManager.getContext())
|
||||
.setDestination(TetherSettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.tether_settings_title_all)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
final Context context = mManager.getContext();
|
||||
final EnforcedAdmin admin = RestrictedLockUtils.checkIfRestrictionEnforced(context,
|
||||
UserManager.DISALLOW_CONFIG_TETHERING, UserHandle.myUserId());
|
||||
if (admin != null) {
|
||||
RestrictedLockUtils.sendShowAdminSupportDetailsIntent(context, admin);
|
||||
} else {
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(
|
||||
Context.CONNECTIVITY_SERVICE);
|
||||
cm.stopTethering(ConnectivityManager.TETHERING_WIFI);
|
||||
setActive(false);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_HOTSPOT;
|
||||
}
|
||||
|
||||
public static class Receiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
|
||||
ConditionManager.get(context).getCondition(HotspotCondition.class)
|
||||
.refreshState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* 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.dashboard.conditional;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import com.android.internal.app.ColorDisplayController;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.display.NightDisplaySettings;
|
||||
|
||||
public final class NightDisplayCondition extends Condition
|
||||
implements ColorDisplayController.Callback {
|
||||
|
||||
private ColorDisplayController mController;
|
||||
|
||||
NightDisplayCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mController = new ColorDisplayController(manager.getContext());
|
||||
mController.setListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_NIGHT_DISPLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_settings_night_display);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_night_display_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_night_display_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {mManager.getContext().getString(R.string.condition_turn_off)};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
new SubSettingLauncher(mManager.getContext())
|
||||
.setDestination(NightDisplaySettings.class.getName())
|
||||
.setSourceMetricsCategory(MetricsEvent.DASHBOARD_SUMMARY)
|
||||
.setTitleRes(R.string.night_display_title)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.launch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
mController.setActivated(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
setActive(mController.isActivated());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivated(boolean activated) {
|
||||
refreshState();
|
||||
}
|
||||
}
|
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.dashboard.conditional;
|
||||
|
||||
import static android.content.Context.NOTIFICATION_SERVICE;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerMutedCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
private final NotificationManager mNotificationManager;
|
||||
|
||||
RingerMutedCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
mNotificationManager =
|
||||
(NotificationManager) mManager.getContext().getSystemService(NOTIFICATION_SERVICE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
int zen = Settings.Global.ZEN_MODE_OFF;
|
||||
if (mNotificationManager != null) {
|
||||
zen = mNotificationManager.getZenMode();
|
||||
}
|
||||
final boolean zenModeEnabled = zen != Settings.Global.ZEN_MODE_OFF;
|
||||
final boolean isSilent =
|
||||
mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT;
|
||||
setActive(isSilent && !zenModeEnabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_MUTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_notifications_off_24dp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getText(R.string.condition_device_muted_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getText(R.string.condition_device_muted_summary);
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.dashboard.conditional;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class RingerVibrateCondition extends AbnormalRingerConditionBase {
|
||||
|
||||
RingerVibrateCondition(ConditionManager manager) {
|
||||
super(manager);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
setActive(mAudioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsProto.MetricsEvent.SETTINGS_CONDITION_DEVICE_VIBRATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_volume_ringer_vibrate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getText(R.string.condition_device_vibrate_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getText(R.string.condition_device_vibrate_summary);
|
||||
}
|
||||
}
|
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* 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.dashboard.conditional;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class WorkModeCondition extends Condition {
|
||||
|
||||
private UserManager mUm;
|
||||
private UserHandle mUserHandle;
|
||||
|
||||
public WorkModeCondition(ConditionManager conditionManager) {
|
||||
super(conditionManager);
|
||||
mUm = (UserManager) mManager.getContext().getSystemService(Context.USER_SERVICE);
|
||||
}
|
||||
|
||||
private void updateUserHandle() {
|
||||
List<UserInfo> profiles = mUm.getProfiles(UserHandle.myUserId());
|
||||
final int profilesCount = profiles.size();
|
||||
mUserHandle = null;
|
||||
for (int i = 0; i < profilesCount; i++) {
|
||||
UserInfo userInfo = profiles.get(i);
|
||||
if (userInfo.isManagedProfile()) {
|
||||
// We assume there's only one managed profile, otherwise UI needs to change.
|
||||
mUserHandle = userInfo.getUserHandle();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refreshState() {
|
||||
updateUserHandle();
|
||||
setActive(mUserHandle != null && mUm.isQuietModeEnabled(mUserHandle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getIcon() {
|
||||
return mManager.getContext().getDrawable(R.drawable.ic_signal_workmode_enable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
return mManager.getContext().getString(R.string.condition_work_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return mManager.getContext().getString(R.string.condition_work_summary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence[] getActions() {
|
||||
return new CharSequence[] {
|
||||
mManager.getContext().getString(R.string.condition_turn_on)
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrimaryClick() {
|
||||
mManager.getContext().startActivity(new Intent(mManager.getContext(),
|
||||
Settings.AccountDashboardActivity.class)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActionClick(int index) {
|
||||
if (index == 0) {
|
||||
if (mUserHandle != null) {
|
||||
mUm.requestQuietModeEnabled(false, mUserHandle);
|
||||
}
|
||||
setActive(false);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unexpected index " + index);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsConstant() {
|
||||
return MetricsEvent.SETTINGS_CONDITION_WORK_MODE;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user